• 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.
13:24:16.762 INFO  [main] - Server accepting connections on tcp://
13:24:16.778 INFO  [main] - JNDI service accepting connections on tcp://64.139.1
13:24:16.778 INFO  [main] - Admin service accepting connections on tcp://64.139.
13:24:17.340 INFO  [main] - Server accepting connections on rmi://
13:24:17.356 INFO  [main] - JNDI service accepting connections on rmi://64.139.1
13:24:17.356 INFO  [main] - Admin service accepting connections on rmi://64.139.

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;
                  // create a JNDI context
                  Hashtable properties = new Hashtable();
                  Context context = new InitialContext(properties);
                  // retrieve queue connection factory
                  QueueConnectionFactory queueConnectionFactory =
                  // 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
                  // start delivery of incoming messages
            catch (NamingException e)
            catch (JMSException e)
      public static void main(String[] args)
            System.out.println("Example to asynchronously listen to a queue.");
                  QueueReceiveAsynchronous listener = new QueueReceiveAsynchronous();

            catch (InterruptedException e)
      // process incoming messages
      public void onMessage(Message message)
                  String messageText = null;
                  if (message instanceof TextMessage)
                        messageText = ((TextMessage)message).getText();
            catch (JMSException e)

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:
        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
        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
  • 2
1 Solution
you're missing (in your classpath) the jar for your context factory

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.
> 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.
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