3 Replies - 1744 Views - Last Post: 13 August 2012 - 05:36 PM

#1 leoujjawal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-August 12

JMS - Class not insatntiated

Posted 08 August 2012 - 11:13 PM

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

Is This A Good Question/Topic? 0
  • +

Replies To: JMS - Class not insatntiated

#2 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,055
  • Joined: 28-December 10

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

Was This Post Helpful? 0
  • +
  • -

#3 RCR  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 33
  • Joined: 04-July 12

Re: JMS - Class not insatntiated

Posted 13 August 2012 - 05:19 PM

View PostfromTheSprawl, 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
Was This Post Helpful? 0
  • +
  • -

#4 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,055
  • Joined: 28-December 10

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. ^^
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1