2

I'm trying to connect JNDI using jnp protocol at JBoss EAP 6.3.2. My code is

Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
        "org.jnp.interfaces.NamingContextFactory");
p.put(Context.URL_PKG_PREFIXES,
        "org.jboss.naming:org.jnp.interfaces");
p.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");

InitialContext ctx = new InitialContext(p);
MyBeanHome home = (MyBeanHome) ctx
                .lookup("/MyApp/MyAppModule/MyBean!org.com.SesFacade.MyBeanHome");

But I'm getting Exception when I'm trying to create an InitialContext object using jnp properties.

javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]

1 Answers1

1

Well Nobody came to answer and finally I found a solution. We need to use remote protocol instead of jnp as follows:

    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY,
            "org.jboss.naming.remote.client.InitialContextFactory");
    p.put(Context.URL_PKG_PREFIXES,
            "org.jboss.as.naming.interfaces:org.jboss.ejb.client.naming");
    p.put(Context.PROVIDER_URL, "remote://localhost:4447");
    p.put("jboss.naming.client.ejb.context", true);
    InitialContext ctx = new InitialContext(p);
  • This SO post was useful for me: https://stackoverflow.com/questions/20784480/cannot-instantiate-initialcontext-with-jboss-server – dan Mar 02 '18 at 19:38