简体   繁体   English

无法找到JMS聊天应用程序的JNDI资源

[英]Unable to find JNDI resource for JMS Chat Application

I am trying to develop a JMS application that runs on Glassfish 3. Eclipse Indigo is my IDE. 我正在尝试开发在Glassfish 3上运行的JMS应用程序.Eclipse Indigo是我的IDE。 I have tried to run this example . 我试图运行这个例子 If you find it necessary, I will copy the code here. 如果您觉得有必要,我会在这里复制代码。 I do not understand exactly what should I do with JNDI. 我不明白我应该怎么做JNDI。 I have created through the Admin Console the two needed resources with the exact specified names, but I get this exception: 我通过管理控制台创建了具有确切指定名称的两个所需资源,但是我得到了以下异常:

java.lang.RuntimeException: Orb initialization erorr
at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:180)
at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:365)
at com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:372)
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at Chat.<init>(Chat.java:38)
at Chat.main(Chat.java:113)
Caused by: java.lang.NullPointerException
at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:152)
... 9 more
javax.naming.NamingException: Lookup failed for 'TopicConnectionFactory' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at Chat.<init>(Chat.java:38)
at Chat.main(Chat.java:113)
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:352)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
... 4 more
Caused by: java.lang.RuntimeException: Orb initialization erorr
at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:180)
at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:365)
at com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:372)
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
... 5 more
Caused by: java.lang.NullPointerException
at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:152)
... 9 more

From what I have read, on a server, the InitialContext should work automatically. 根据我的阅读,在服务器上,InitialContext应该自动运行。

What am I doing wrong? 我究竟做错了什么?

Upon constructing the InitialContext you need to provide some properties that describes how to access and get objects from the JNDI server. 在构造InitialContext您需要提供一些属性来描述如何从JNDI服务器访问和获取对象。

Mainly you need to provide a property that marks the vendor's implementation and another that points to the data store location, and you may need to specify other security or vendor specific properties. 主要是您需要提供标记供应商实现的属性和指向数据存储位置的另一个属性,并且您可能需要指定其他安全性或供应商特定属性。

In your case (glassfish), I think the following properties needs to be set: 在你的情况下(glassfish),我认为需要设置以下属性:

// the initial context factory, choosing the glassfish implementation
env.setProperty("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");
// glassfish's server location
env.setProperty("org.omg.CORBA.ORBInitialHost", "<host name or IP>");
env.setProperty("org.omg.CORBA.ORBInitialPort", "<port number>"); // default is 3700  

I hope this code will helped you,my environment : JEE6+glassfish3V 我希望这段代码能帮到你,我的环境:JEE6 + glassfish3V

 private static ConnectionFactory connectionFactory;
 private static Queue queue;
 public static void main(String[] args) throws NamingException {
      Connection connection = null;
      Session session = null;
      MessageConsumer consumer = null;
      TextMessage message = null;

      Properties env = new Properties();

      //glassfish3V
      env.put(Context.PROVIDER_URL, "iiop://localhost:8080");
      InitialContext jndi = new InitialContext(env);
      connectionFactory = (ConnectionFactory) jndi.lookup("jms/ConnectionFactory");
      queue = (Queue) jndi.lookup("jms/Queue"); // put your Queue here


      try {
           connection = connectionFactory.createConnection();
           session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
           consumer = session.createConsumer(queue);
           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.err.println("Exception occurred: " + e.toString());
      } finally {
           if (connection != null) {
                try {
                     connection.close();
                } catch (JMSException e) {
                }
           }
      }
 }

It turned out to be a JAR problem with my classpath. 事实证明,我的类路径是一个JAR问题。 The needed JARs are the one specified in the question, and the other two in the accepted answer here , namely: gf-client-module.jar , imqjmsra.jar and imqbroker.jar . 所需要的JAR文件是在接受答案的一个问题中指定的,其他两个位置 ,即: gf-client-module.jarimqjmsra.jarimqbroker.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM