Hi I am writing this code to send a message to GlassFish queue :
package com.wipro.JMSExample;
// import java.util.Properties;
import java.util.Properties;
import javax.jms.*;
import javax.naming.*;
public class HelloMsg {
public static void main(String args[]) throws Exception {
Properties env = new Properties();
env.setProperty("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");
env.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
env.setProperty("org.omg.CORBA.ORBInitialPort","3700");
Context ctx = new InitialContext(env);
QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup("jms/GlassFishConnectionFactory");
QueueConnection conn = connFactory.createQueueConnection();
QueueSession session = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) ctx.lookup("jms/GlassFishQueue");
// Sender
QueueSender sender = session.createSender(queue);
TextMessage msg = session.createTextMessage();
msg.setText("Hello there!");
System.out.println("Sending the message: "+msg.getText());
sender.send(msg);
// Receiver
QueueReceiver receiver = session.createReceiver(queue);
conn.start();
Message m = receiver.receive();
if(m instanceof TextMessage) {
TextMessage txt = (TextMessage) m;
System.out.println("Message Received: "+txt.getText());
}
session.close();
conn.close();
}
}
I have included appserv-rt.jar as well...
The Error is :
Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:197)
at com.wipro.JMSExample.HelloMsg.main(HelloMsg.java:22)
Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at com.sun.naming.internal.Versionhelper12.loadClass(Versionhelper12.java:46)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
... 4 more
JMS - Class not insatntiated
Page 1 of 13 Replies - 1422 Views - Last Post: 13 August 2012 - 05:36 PM
Replies To: JMS - Class not insatntiated
#2
Re: JMS - Class not insatntiated
Posted 09 August 2012 - 01:17 AM
Are you using Eclipse? If you already tried adding the jar file to your build path I suggest trying to add it on your /WEB-INF/lib folder as well.
This post has been edited by fromTheSprawl: 09 August 2012 - 05:30 PM
#3
Re: JMS - Class not insatntiated
Posted 13 August 2012 - 05:19 PM
fromTheSprawl, on 09 August 2012 - 01:17 AM, said:
Are you using Eclipse? If you already tried adding the jar file to your build path I suggest trying to add it on your /WEB-INF/lib folder as well.
The one part that seemed fishy to me was:
Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory]
[Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory]
But I don't work with Glassfish, just my two cents.
- RCR
#4
Re: JMS - Class not insatntiated
Posted 13 August 2012 - 05:36 PM
Yep, that could be it too. I don't work with GlassFish either.
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote





|