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

Posted on 2007-10-14
Last Modified: 2013-11-13
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(
Caused by: java.lang.ClassNotFoundException: org.exolab.jms.jndi.InitialContextF
        at$ Source)
        at Method)
        at 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
Question by:mmingfeilam
    LVL 92

    Expert Comment

    you're missing (in your classpath) the jar for your context factory


    Author Comment

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

    Accepted Solution

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now