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

x
?
Solved

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

Posted on 2007-10-14
3
Medium Priority
?
2,688 Views
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.
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
Comment
Question by:mmingfeilam
  • 2
3 Comments
 
LVL 92

Expert Comment

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

                  properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.exolab.jms.jndi.InitialContextFactory");
0
 

Author Comment

by:mmingfeilam
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.
0
 
LVL 92

Accepted Solution

by:
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.
0

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