i am new for Jms. I downloaded jms tutorial from sun web site, when i coded first jms application using this tutorial,i get an exception.My code is like this. Exception is Naming Exception:
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 Exception in thread "main" java.lang.NullPointerException.
My code:
public class SampleClass1 {
public static void main(String[] args) throws NamingException, JMSException {
Context context=new InitialContext();
QueueConnectionFactory queueConnectionFactory=(QueueConnectionFactory)context.lookup("QueueConnectionFactory");
Queue queue=(Queue) context.lookup("MyQueue");
QueueConnection queueConnection=(QueueConnection) queueConnectionFactory.createQueueConnection();
QueueSession queueSession=queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
QueueSender queueSender=queueSession.createSender(queue);
Message message=(Message) queueSession.createTextMessage("Hello Word");
queueSender.send((javax.jms.Message) message);
QueueReceiver queueReceiver=queueSession.createReceiver(queue);
queueConnection.start();
Message receivedMessage=(Message) queueReceiver.receive();
System.out.println(receivedMessage.toString());
}
}