JMS example
Hi
I am new to JMS in Sun One 7 . I want to run the simpleprogram shown below
import javax.naming.*;
import javax.jms.*;
import java.util.*;
publicclass SimpleMessageClient
{
publicstaticvoid main (String a[])
{
try
{
Properties prop =new Properties ();
prop.put (Context.INITIAL_CONTEXT_FACTORY,
"com.sun.enterprise.naming.SerialInitContextFactory");
prop.put (Context.PROVIDER_URL,"localhost:1050");
prop.put (Context.SECURITY_AUTHENTICATION,"simple");
prop.put (Context.SECURITY_PRINCIPAL,"admin");
prop.put (Context.SECURITY_CREDENTIALS,"adminadmin");
Context jndiContext=new InitialContext (prop);
QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory)jndiContext.lookup ("java:comp/env/jms/QueueConnectionFactory");
Queue queue =(Queue)jndiContext.lookup ("java:comp/env/jms/Queue");
QueueConnection queueConnection = queueConnectionFactory.createQueueConnection ();
QueueSession queueSession = queueConnection.createQueueSession (false,Session.AUTO_ACKNOWLEDGE);
QueueSender queueSender = queueSession.createSender (queue);
TextMessage message =queueSession.createTextMessage ();
for(int i=0;i<10;i++)
{
message.setText ("Message "+i);
System.out.println ("Sending the message "+message.getText ());
queueSender.send (message);
}
}catch (Exception e)
{
e.printStackTrace ();
}
}
}
I am getting the exception below
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory. Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:217)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at SimpleMessageClient.main(SimpleMessageClient.java:20)
Please help me
I have set jms.jar and imq.jar in the class path. I searched for jndi.jar but not able to find
I have doubt in instantiating the InitialContext
Properties prop = new Properties ();
prop.put (Context.INITIAL_CONTEXT_FACTORY,
"com.sun.enterprise.naming.SerialInitContextFactory");
prop.put (Context.PROVIDER_URL, "localhost:1050");
prop.put (Context.SECURITY_AUTHENTICATION, "simple");
prop.put (Context.SECURITY_PRINCIPAL, "admin");
prop.put (Context.SECURITY_CREDENTIALS, "adminadmin");
Context jndiContext= new InitialContext (prop);
Can any one explain the variable that are set
Thanks and regards
Suneesh VR

