Hello All,
I am trying to get an application of mine to publish to a JMS topic. I am using OpenJMS.
Here is the code I am using to get the javax.jms.Connection:
Hashtable props = new Hashtable();
props.put(Context.PROVIDER_URL, "tcp://localhost:3035/");
props.put("java.naming.factory.initial", "org.exolab.jms.jndi.InitialContextFactory");
props.put("java.naming.security.principal", "admin");
props.put("java.naming.security.credentials","openjms");
context = new InitialContext(props);
// look up the ConnectionFactory
ConnectionFactory factory = (ConnectionFactory) context.lookup("ConnectionFactory");
// create the connection
connection = factory.createConnection();
When I run this code I get the following exception:
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 cma.live.CmaLiveClient.<init>(CmaLiveClient.java:41)
at cma.trade.CmaTradeClient.<init>(CmaTradeClient.java:24)
at cma.tradelog.PW_TradeHandler.startJMS(PW_TradeHandler.java:201)
at cma.tradelog.PW_TradeHandler.access$100(PW_TradeHandler.java:38)
at cma.tradelog.PW_TradeHandler$2.run(PW_TradeHandler.java:225)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.exolab.jms.jndi.InitialContextFactory
at com.sun.jnlp.JNLPClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.sun.jnlp.JNLPClassLoader.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)
... 11 more
This looks like a simple case of the correct jar file not being in my classpath. But the following code runs perfectly:
javax.naming.spi.InitialContextFactory initial_context_factory =
(javax.naming.spi.InitialContextFactory)
Class.forName("org.exolab.jms.jndi.InitialContextFactory").newInstance();
org.exolab.jms.jndi.InitialContextFactory exolab_initial_context_factory =
(org.exolab.jms.jndi.InitialContextFactory)
Class.forName("org.exolab.jms.jndi.InitialContextFactory").newInstance();
I have googled around a bit and found a handful of other people who have had the same problem. For instance, check out [this thread|http://fixunix.com/weblogic/221703-javax-naming-noinitialcontextexception-cannot-instantiate-class-weblogic-jndi-wlinitialcontextfactory-root-exception-java-lang-classnotfoundexception-weblogic-jndi-wlinitialcontextfactory.html] .
The issue seems to occur when the program runs inside another environment. The guy in the thread referenced above is using WebLogic. I'm trying to run my code inside Portware, which is a java application used for stock trading. I basically load my code into Portware and it runs inside the Portware environment. I have access to all the Portware classes and so forth. It appears that OpenJMS does not adapt well to being run inside an environment that controls that classpath.
If anyone has any ideas about how I can hack my way around this problem, I would greatly appreciate it. How can I figure out what classpath the OpenJMS stuff is trying to use? It is obviously not using the one that is defined by the environment it is running in.
Thanks.