I am new-bee in JMS and trying to execute my first JMS program using Glassfish application server.
I have created Connection factory [jms/MyQueueFactory] and Destination resource [jms/myQueue] in Glassfish admin console as per following:
Following is my code:
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.naming.InitialContext;
public class MyReceiver
{
public static void main(String[] args)
{
try
{
InitialContext ctx = new InitialContext();
QueueConnectionFactory f = (QueueConnectionFactory)ctx.lookup("jms/MyQueueFactory"); **// Getting error here**
QueueConnection con = f.createQueueConnection();
con.start();
QueueSession session = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue t = (Queue)ctx.lookup("jms/myQueue");
QueueReceiver receiver = session.createReceiver(t);
MyListener listner = new MyListener();
receiver.setMessageListener(listner);
System.out.println("Receiver1 is ready, waiting for messages...");
System.out.println("press Ctrl+c to shutdown...");
while(true)
{
Thread.sleep(1000);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
But when I try to execute it gives me following error:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(Unknown Source) at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.lookup(Unknown Source) at com.test.MyReceiver.main(MyReceiver.java:16)
Please let me know what I am missing here.
Thanks.
appclient
? – Thufir