• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2822
  • Last Modified:

Cannot instantiate class: org.exolab.jms.jndi.InitialContextFactory

i finally got the openjms server to work:

OpenJMS 0.7.7-beta-1
The OpenJMS Group. (C) 1999-2007. All rights reserved.
http://openjms.sourceforge.net
13:24:16.762 INFO  [main] - Server accepting connections on tcp://64.139.12.19:3
035/
13:24:16.778 INFO  [main] - JNDI service accepting connections on tcp://64.139.1
2.19:3035/
13:24:16.778 INFO  [main] - Admin service accepting connections on tcp://64.139.
12.19:3035/
13:24:17.340 INFO  [main] - Server accepting connections on rmi://64.139.12.19:1
099/
13:24:17.356 INFO  [main] - JNDI service accepting connections on rmi://64.139.1
2.19:1099/
13:24:17.356 INFO  [main] - Admin service accepting connections on rmi://64.139.
12.19:1099/

but when i run this:
import java.util.Hashtable;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class QueueReceiveAsynchronous implements MessageListener
{
      
      private QueueConnection queueConnection;
      private QueueSession queueSession;
      private Queue queue;
      private QueueReceiver queueReceiver;
            
      QueueReceiveAsynchronous()
      {
            try
            {
                  // create a JNDI context
                  Hashtable properties = new Hashtable();
                  properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.exolab.jms.jndi.InitialContextFactory");
                  properties.put(Context.PROVIDER_URL,"rmi://localhost:1099/");
                  Context context = new InitialContext(properties);
                  
                  // retrieve queue connection factory
                  QueueConnectionFactory queueConnectionFactory =
                                          (QueueConnectionFactory)context.lookup("JmsQueueConnectionFactory");
                  // create a queue connection
                  queueConnection = queueConnectionFactory.createQueueConnection();
                  
                  // create a queue session
                  // set transactions to false and set auto acknowledgement of receipt of messages
                  queueSession = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
                  
                  // retrieve queue
                  queue = (Queue)context.lookup("queue1");
                  
                  // create a queue receiver and associate to the retrieved queue
                  queueReceiver = queueSession.createReceiver(queue);
                  
                  // associate message listener
                  queueReceiver.setMessageListener(this);
                  
                  // start delivery of incoming messages
                  queueConnection.start();
            }
            catch (NamingException e)
            {
                  e.printStackTrace();
            }
            catch (JMSException e)
            {
                  e.printStackTrace();
            }
      }      
                  
      public static void main(String[] args)
      {
            System.out.println("Example to asynchronously listen to a queue.");
            try
            {
                  QueueReceiveAsynchronous listener = new QueueReceiveAsynchronous();
                  Thread.currentThread().sleep(2000);
            }

            catch (InterruptedException e)
            {
                  e.printStackTrace();
            }
      }
      
      // process incoming messages
      public void onMessage(Message message)
      {
            try
            {
                  String messageText = null;
                  if (message instanceof TextMessage)
                        messageText = ((TextMessage)message).getText();
                  System.out.println(messageText);
            }
            catch (JMSException e)
            {
                  e.printStackTrace();
            }
      }
}

i get this:

C:\Projects\Leader\prototype\jms\openjms2>java TopicPublish
javax.naming.NoInitialContextException: Cannot instantiate class: org.exolab.jms
.jndi.InitialContextFactory [Root exception is java.lang.ClassNotFoundException:
 org.exolab.jms.jndi.InitialContextFactory]
        at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
        at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
        at javax.naming.InitialContext.init(Unknown Source)
        at javax.naming.InitialContext.<init>(Unknown Source)
        at TopicPublish.main(TopicPublish.java:27)
Caused by: java.lang.ClassNotFoundException: org.exolab.jms.jndi.InitialContextF
actory
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
        ... 5 more
0
mmingfeilam
Asked:
mmingfeilam
  • 2
1 Solution
 
objectsCommented:
you're missing (in your classpath) the jar for your context factory

                  properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.exolab.jms.jndi.InitialContextFactory");
0
 
mmingfeilamAuthor Commented:
i don't know which jar is it, and i put the %OPENJMS_HOME%\lib into the class path, the program should be able to access all the jar file in that directory.  other than the jar files in that directory, i don't know where it could be.
0
 
objectsCommented:
> i put the %OPENJMS_HOME%\lib into the class path

that will only add the class files in directory, not the jars.
jars needs to be added individually.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now