9

When i run a JMS related application, i am encountering the following exception 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

We are using Sun Application Server 9.1

Any idea what are we missing?

I already tried adding the following but result still the same

    Properties env = new Properties();
    env.put("java.naming.factory.initial","com.sun.jndi.cosnaming.CNCtxFactory");

    Context ctx = new InitialContext(env);
  • 2
    Not a complete duplicate: the specifics of what properties to set for this app server are not given over there. At first sight the questioner is doing what is recommended, and is consistent with the Sun docs. – djna Jan 04 '10 at 08:28
  • Not a complete duplicate. You need to put jndi.properties file in classpath. For more info use following link. https://cwiki.apache.org/confluence/display/qpid/How+to+Use+JNDI Specify your naming factory & queue name. Should work fine. – Vaibhav Jain Aug 11 '15 at 10:01

3 Answers3

7

A very common error can be that you have not added the jboss-client.jar! or alternate jar if using weblogic.

3

I was facing the same problrm while working with spring & weblogic . I had resolved it by setting two properties

System.getProperties().put("java.naming.factory.initial","weblogic.jndi.WLInitialContextFactory"); System.getProperties().put("java.naming.provider.url", "t3://localhost:80")

Saurabh
  • 31
  • 2
0

In my environment, setting Context.INITIAL_CONTEXT_FACTORY wasn't enough. I also had to set Context.URL_PKG_PREFIXES, explained at http://docs.oracle.com/javase/6/docs/api/javax/naming/Context.html#URL_PKG_PREFIXES.

Nikhil
  • 16,194
  • 20
  • 64
  • 81
Michael
  • 347
  • 2
  • 13