javajbosswildflyjndi

javax.naming.NamingException: WFLYNAM0027: Failed instantiate InitialContextFactory


I am using wildfly10. This is my java code.

private Hashtable mEnv = new Hashtable();
InitialContext e = new InitialContext(mEnv);

The mEnv's value as flow.

mEnv = {
      java.naming.provider.url=localhost:8080,
       java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, 
      java.naming.security.authentication=simple,
      java.naming.security.principal=fc,
      java.naming.security.credentials=1234

} When I run this command , I have such error.

javax.naming.NamingException: WFLYNAM0027: Failed instantiate InitialContextFactory org.jnp.interfaces.NamingContextFactory from classloader ModuleClassLoader for Module "deployment.cppro.war:main" from Service Module Loader [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory from [Module "deployment.cppro.war:main" from Service Module Loader]]
java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory from [Module "deployment.cppro.war:main" from Service Module Loader]
WFLYNAM0027: Failed instantiate InitialContextFactory org.jnp.interfaces.NamingContextFactory from classloader ModuleClassLoader for Module "deployment.cppro.war:main" from Service Module Loader
null
null

Please help me. thanks.


Solution

  • JNP is the old naming protocol for JBoss AS5. You have to use the new JNDI properties for WildFly 10. Take a look at https://docs.jboss.org/author/display/WFLY/JNDI+Reference (depending on why you need an InitialContext in the first place)