Unable to Initialize InitialContext in JBoss AS 7.1

2.7k views Asked by At

I am unable to initialize InitialContext and lookup for a string. Here is my code snippet :

java.util.Hashtable env = new java.util.Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");
env.put("java.naming.provider.url","remote://localhost:4447");
env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
try
  {    
    if(env != null)
      ic = new InitialContext(env);
    else
      ic = new InitialContext();

this.connectionFactory = (ConnectionFactory)ic.lookup("java:/ConnectionFactory");
this.queue = (javax.jms.Queue)ic.lookup("java:jboss/exported/jms/queue/test");

}catch(Exception e){
e.printStackTrace();
}

Always ic is being null and I am getting Exception NullPointer Exception. Can anyone tell me where the wrong I have done or any configuration? Any suggestion/advice are acceptable.

EDIT :1

20:19:01,678 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)
javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory 
org.jboss.naming.remote.client.InitialContextFactory from classloader 
ModuleClassLoader for Module "deployment.TRH_SAS_V2.war:main" from Service Module 
Loader
20:19:01,682 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) 
at  org.jboss.as.naming.InitialContextFactoryBuilder.createInitialContextFactory(InitialContextFactoryBuilder.java:64)

20:19:01,684 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)

20:19:01,686 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)

20:19:01,688 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at javax.naming.InitialContext.init(Unknown Source)

20:19:01,690 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at javax.naming.InitialContext.<init>(Unknown Source)
1

There are 1 answers

0
Raylite3 On

It looks like you don't have the InitialContextFactory class on your classpath. The jar you need will be in the bin/client directory of your JBoss installation. See this link for details : https://docs.jboss.org/author/display/AS72/JNDI+Reference