Michael Lam
asked on
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.QueueConnectionF actory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContex t;
import javax.naming.NamingExcepti on;
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.INI TIAL_CONTE XT_FACTORY ,"org.exol ab.jms.jnd i.InitialC ontextFact ory");
properties.put(Context.PRO VIDER_URL, "rmi://loc alhost:109 9/");
Context context = new InitialContext(properties) ;
// retrieve queue connection factory
QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory)co ntext.look up("JmsQue ueConnecti onFactory" );
// create a queue connection
queueConnection = queueConnectionFactory.cre ateQueueCo nnection() ;
// create a queue session
// set transactions to false and set auto acknowledgement of receipt of messages
queueSession = queueConnection.createQueu eSession(f alse,Sessi on.AUTO_AC KNOWLEDGE) ;
// retrieve queue
queue = (Queue)context.lookup("que ue1");
// create a queue receiver and associate to the retrieved queue
queueReceiver = queueSession.createReceive r(queue);
// associate message listener
queueReceiver.setMessageLi stener(thi s);
// 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("Exampl e to asynchronously listen to a queue.");
try
{
QueueReceiveAsynchronous listener = new QueueReceiveAsynchronous() ;
Thread.currentThread().sle ep(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).get Text();
System.out.println(message Text);
}
catch (JMSException e)
{
e.printStackTrace();
}
}
}
i get this:
C:\Projects\Leader\prototy pe\jms\ope njms2>java TopicPublish
javax.naming.NoInitialCont extExcepti on: Cannot instantiate class: org.exolab.jms
.jndi.InitialContextFactor y [Root exception is java.lang.ClassNotFoundExc eption:
org.exolab.jms.jndi.Initia lContextFa ctory]
at javax.naming.spi.NamingMan ager.getIn itialConte xt(Unknown Source)
at javax.naming.InitialContex t.getDefau ltInitCtx( Unknown Source)
at javax.naming.InitialContex t.init(Unk nown Source)
at javax.naming.InitialContex t.<init>(U nknown Source)
at TopicPublish.main(TopicPub lish.java: 27)
Caused by: java.lang.ClassNotFoundExc eption: org.exolab.jms.jndi.Initia lContextF
actory
at java.net.URLClassLoader$1. run(Unknow n Source)
at java.security.AccessContro ller.doPri vileged(Na tive Method)
at java.net.URLClassLoader.fi ndClass(Un known Source)
at java.lang.ClassLoader.load Class(Unkn own Source)
at sun.misc.Launcher$AppClass Loader.loa dClass(Unk nown Source)
at java.lang.ClassLoader.load Class(Unkn own Source)
at java.lang.ClassLoader.load ClassInter nal(Unknow n Source)
at java.lang.Class.forName0(N ative Method)
at java.lang.Class.forName(Un known Source)
at com.sun.naming.internal.Ve rsionHelpe r12.loadCl ass(Unknow n Source)
... 5 more
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.QueueConnectionF
import javax.jms.QueueReceiver;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContex
import javax.naming.NamingExcepti
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.INI
properties.put(Context.PRO
Context context = new InitialContext(properties)
// retrieve queue connection factory
QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory)co
// create a queue connection
queueConnection = queueConnectionFactory.cre
// create a queue session
// set transactions to false and set auto acknowledgement of receipt of messages
queueSession = queueConnection.createQueu
// retrieve queue
queue = (Queue)context.lookup("que
// create a queue receiver and associate to the retrieved queue
queueReceiver = queueSession.createReceive
// associate message listener
queueReceiver.setMessageLi
// 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("Exampl
try
{
QueueReceiveAsynchronous listener = new QueueReceiveAsynchronous()
Thread.currentThread().sle
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
// process incoming messages
public void onMessage(Message message)
{
try
{
String messageText = null;
if (message instanceof TextMessage)
messageText = ((TextMessage)message).get
System.out.println(message
}
catch (JMSException e)
{
e.printStackTrace();
}
}
}
i get this:
C:\Projects\Leader\prototy
javax.naming.NoInitialCont
.jndi.InitialContextFactor
org.exolab.jms.jndi.Initia
at javax.naming.spi.NamingMan
at javax.naming.InitialContex
at javax.naming.InitialContex
at javax.naming.InitialContex
at TopicPublish.main(TopicPub
Caused by: java.lang.ClassNotFoundExc
actory
at java.net.URLClassLoader$1.
at java.security.AccessContro
at java.net.URLClassLoader.fi
at java.lang.ClassLoader.load
at sun.misc.Launcher$AppClass
at java.lang.ClassLoader.load
at java.lang.ClassLoader.load
at java.lang.Class.forName0(N
at java.lang.Class.forName(Un
at com.sun.naming.internal.Ve
... 5 more
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
properties.put(Context.INI