Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What is a javax.naming. NoInitialContextException ??  RSS feed

 
Patrick ODonnell
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the following error mean and how can it be fixed??
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
Thanks,
Patrick.
 
Tiger Scott
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You hav eto setup the intial context before you can use it. Classname /provider etc.
A weblogic example-
public Context getInitialContext() throws Exception { Hashtable myEnvironment = new Hashtable(); myEnvironment.put(Context.PROVIDER_URL, "wlepool://myPool"); myEnvironment.put(Context.INITIAL_CONTEXT_FACTORY, "com.beasys.jndi.WLEInitialContextFactory"); myEnvironment.put(Context.SECURITY_AUTHENTICATION, "securityStyle"); myEnvironment.put(Context.SECURITY_PRINCIPAL, "username"); myEnvironment.put(Context.SECURITY_CREDENTIALS, "password"); return new InitialContext(myEnvironment);}
HTH
 
Ram Dhan Yadav K
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanjay is correct.
Problem: You get a NoInitialContextException.
Cause: You did not specify which implementation to use for the initial context. Specifically, the Context.INITIAL_CONTEXT_FACTORY environment property was not set to the class name of the factory that will create the initial context. Or, you did not make available to the program the classes of the service provider named by Context.INITIAL_CONTEXT_FACTORY.
Solution: Set the Context.INITIAL_CONTEXT_FACTORY environment property to the class name of the initial context implementation that you are using. See this Link: http://java.sun.com/products/jndi/tutorial/getStarted/faq/runtime.html
If the property was set, then make sure that the class name was not mistyped, and that the class named is available to your program (either in its classpath or installed in the jre/lib/ext directory of the JRE). The Java 2 SDK, v1.3 includes service providers for LDAP, COS naming, and the RMI registry. All other service providers must be installed and added to the execution environment.
You can find JNDI information in this tutorial.
http://java.sun.com/products/jndi/tutorial/
 
Patrick ODonnell
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
That was very helpful
 
Ashish Jaiman
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This exception is thrown when no initial context implementation can be created. The policy of how an initial context implementation is selected is described in the documentation of the InitialContext class.
This exception can be thrown during any interaction with the InitialContext, not only when the InitialContext is constructed. For example, the implementation of the initial context might lazily retrieve the context only when actual methods are invoked on it. The application should not have any dependency on when the existence of an initial context is determined.
Synchronization and serialization issues that apply to NamingException apply directly here.
 
Ram Dhan Yadav K
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ashish,
Synchronization and serialization issues that apply to NamingException apply directly here
what do you mean by this statement? Can you please explain it!
the implementation of the initial context might lazily retrieve the context only when actual methods are invoked on it
Does this statement means that, NoInitialContextException is thrown even while lazy loading?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!