JBAS011843: Failed instantiate InitialContextFactory org.jnp.interfaces.NamingContextFactory in JBoss EAP 6

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x

Issue

  • We are seeing this exception when our application tries to create an InitialContext :
javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory org.jnp.interfaces.NamingContextFactory from classloader ModuleClassLoader for Module "deployment.test-app.jar:main" from Service Module Loader
 	at org.jboss.as.naming.InitialContextFactoryBuilder.createInitialContextFactory(InitialContextFactoryBuilder.java:64)
 	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:664)
 	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
 	at javax.naming.InitialContext.init(InitialContext.java:223)
 	at javax.naming.InitialContext.<init>(InitialContext.java:197)
        ...

Resolution

If you are wanting to lookup something in the JNDI that your application is running in, you should not pass any properties into new InitialContext().

Remove the jndi.properties from your application, this file should not be included in an application running in JBoss EAP as it will globally change the JNDI environment for the entire application server.

Remove the system property -Djava.naming.factory.initial=... as this also changes the global JNDI environment.

Change your client code that creates the InitialContext where it is specifying java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, to use either ejb-client 1 if making an EJB call or remote-naming if looking up an MDB or other non Session EJB.

There is a byteman script which can be used to help locate what is changing the settings if it is not easily located2.

Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.