Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
即使添加了jar文件,也无法编译java项目?_Java_Eclipse_Jms - Fatal编程技术网

即使添加了jar文件,也无法编译java项目?

即使添加了jar文件,也无法编译java项目?,java,eclipse,jms,Java,Eclipse,Jms,我一直在使用jms服务构建项目。我已经在eclipse中创建了这个项目 Project name : JmsTest src->jmstestclient(package)->SimpleProducer.java(class) SimpleProducer.java的代码如下 import javax.jms.*; import javax.naming.*; public class SimpleSynchConsumer { /** * Main met

我一直在使用jms服务构建项目。我已经在eclipse中创建了这个项目

Project name : JmsTest
src->jmstestclient(package)->SimpleProducer.java(class)
SimpleProducer.java的代码如下

import javax.jms.*;
import javax.naming.*;


public class SimpleSynchConsumer {
    /**
     * Main method.
     *
     * @param args     the destination name and type used by the
     *                 example
     */
    public static void main(String[] args) {
        String destName = null;
        Context jndiContext = null;
        ConnectionFactory connectionFactory = null;
        Connection connection = null;
        Session session = null;
        Destination dest = null;
        MessageConsumer consumer = null;
        TextMessage message = null;

        if (args.length != 1) {
            System.out.println("Program takes one argument: <dest_name>");
            System.exit(1);
        }

        destName = new String(args[0]);
        System.out.println("Destination name is " + destName);

        /*
         * Create a JNDI API InitialContext object if none exists
         * yet.
         */
        try {
            jndiContext = new InitialContext();
        } catch (NamingException e) {
            System.out.println("Could not create JNDI API context: " +
                e.toString());
            System.exit(1);
        }

        /*
         * Look up connection factory and destination.  If either
         * does not exist, exit.  If you look up a
         * TopicConnectionFactory or a QueueConnectionFactory,
         * program behavior is the same.
         */
        try {
            connectionFactory = (ConnectionFactory) jndiContext.lookup(
                    "jms/ConnectionFactory");
            dest = (Destination) jndiContext.lookup(destName);
        } catch (Exception e) {
            System.out.println("JNDI API lookup failed: " + e.toString());
            System.exit(1);
        }

        /*
         * Create connection.
         * Create session from connection; false means session is
         * not transacted.
         * Create consumer, then start message delivery.
         * Receive all text messages from destination until
         * a non-text message is received indicating end of
         * message stream.
         * Close connection.
         */
        try {
            connection = connectionFactory.createConnection();
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            consumer = session.createConsumer(dest);
            connection.start();

            while (true) {
                Message m = consumer.receive(1);

                if (m != null) {
                    if (m instanceof TextMessage) {
                        message = (TextMessage) m;
                        System.out.println("Reading message: " +
                            message.getText());
                    } else {
                        break;
                    }
                }
            }
        } catch (JMSException e) {
            System.out.println("Exception occurred: " + e.toString());
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (JMSException e) {
                }
            }
        }
    }
}
它指出了importjavax.jms行上的错误

目前我没有JEE或j2ee。我只安装了jdk,没有安装j2ee。我是否必须安装j2ee来连接JMS服务器


我怎样才能使这个程序可编译

在应用程序的类路径中添加jar。

我是eclipse新手。如何在application@Robinhood跟着这个谢谢你。我能够构建jar文件,代码已经编译。您能建议我如何运行上面的代码来连接JMS服务器吗。我必须安装j2EE吗?上面的代码会将我连接到JMS服务器。@Robinhood如果建议有效,请选择正确答案。您也可以在google上找到许多JMS服务器客户端示例。如果您发现任何pblm plz发布您的问题,请遵循其中一个。谢谢您的帮助。我对JMS有点缺乏经验。使用JMS的基本要求是什么。我已经安装了JEE SDK。我已经按照上面的代码创建了一个项目。但是我对JMS服务感到困惑。我有JMS服务器吗。以及我的队列是如何创建的。我是否必须在JMS服务器上创建队列,或者可以使用java代码创建队列。在上面发布的问题中,它返回System.out.println(“程序接受一个参数:”);输出。我如何知道我的客户端已正确连接到服务器。
The import javax.jms cannot be resolved. 
Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    ConnectionFactory cannot be resolved to a type
    Connection cannot be resolved to a type
    Session cannot be resolved to a type
    Destination cannot be resolved to a type
    MessageConsumer cannot be resolved to a type
    TextMessage cannot be resolved to a type
    ConnectionFactory cannot be resolved to a type
    Destination cannot be resolved to a type
    Session cannot be resolved to a variable
    Message cannot be resolved to a type
    TextMessage cannot be resolved to a type
    TextMessage cannot be resolved to a type
    JMSException cannot be resolved to a type
    JMSException cannot be resolved to a type

    at jmstestclient.SimpleSynchConsumer.main(SimpleSynchConsumer.java:51)