Friday, June 25, 2010

Exception in program: javax.naming.NoInitialContextException

Im running a JMS Application using a queue. 

- It runs Fine.

- BUT when I do a Debug (F7 in netbeans) , It gives an exception in method initJMS()  (code attached).

 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

 private void initJMS() throws JMSException      {          try         {             jndi = new InitialContext();         }         catch(Exception e)         {             JOptionPane.showMessageDialog(null, e);         }         try         {             ConnectionFactory connectionFactory = (ConnectionFactory)jndi.lookup("jms/ConnectionFactory");             Queue queue = (Queue)jndi.lookup("jms/Queue");             connection = connectionFactory.createConnection();                     session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);             dest=(Destination)queue;             producer = session.createProducer(dest);         }          catch(Exception e)         {              System.out.println(e);             JOptionPane.showMessageDialog(null, e);         }     }
 Ans : 
 Thanks for the tidbit.  This is for GlassFish:  Can also see this:
 Ans 1 : 

Try this...

Apparently, my code is out in the car.  But if you scroll to the bottom, you will see an example of putting value in environment using HashTable.

The approach I used was same as that, but instead of Context.Applet, I was using INITIAL_CONTEXT_FACTORY (  In my case I used the context factory for NDS, but you would just put in appropriate value as indicated as a fully qualified classpath to the context factory for your application.

No comments:

Blog Archive