Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2007-10-14
Medium Priority
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(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
Question by:mmingfeilam
  • 2
LVL 92

Expert Comment

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


Author Comment

ID: 20074937
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

objects earned 750 total points
ID: 20075209
> 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.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Starting up a Project
Suggested Courses

578 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