Issue:
When you develop a code for standalone of JMS client. You may got following exception.
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
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
Solution:
Please check if you already correctly initate your QueueConnectionFactory object. Sometimes, you might use the correct context object to init QueueConnectionFactory.
For example,
Context context = new InitialContext(env);
InitialContext ctx= new InitialContext();
QueueConnectionFactory factory = (QueueConnectionFactory) ctx
.lookup("jms/MyQueueFactory");
QueueConnection connection = factory.createQueueConnection();
QueueSession session = connection.createQueueSession(false,
QueueSession.AUTO_ACKNOWLEDGE);
Qu
On line 2, we did not use line 1 object to initate QueueConnectionFactory. Correct initial code should be like this.
Context context = new InitialContext(env);
QueueConnectionFactory factory = (QueueConnectionFactory) context
.lookup("jms/MyQueueFactory");
QueueConnection connection = factory.createQueueConnection();
QueueSession session = connection.createQueueSession(false,
QueueSession.AUTO_ACKNOWLEDGE);