I'm trying to create a InitialContext
so I could ask the JNDI for some enterprise java beans.
The JBoss is running fine, but when I run the java code I get an exception.
I'm running JBoss 7.1
Here is my code:
public class Test {
public static void main(String[] args){
InitialContext ctx=getInitialContext();
Object ref=null;
try {
ref = ctx.lookup("ParamEJB/remote");
} catch (NamingException e) {
System.out.println("Lookup Failed");
e.printStackTrace();
}
Param stub=(Param)PortableRemoteObject.narrow(ref, Param.class);
int times=stub.getTimes();
for(int i=0;i<times;i++)
System.out.println(stub.getMessage());
}
public static InitialContext getInitialContext(){
Hashtable<String,String> h=new Hashtable<String,String>();
h.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
h.put("java.naming.provider.url","localhost");
try {
return new InitialContext(h);
} catch (NamingException e) {
System.out.println("Cannot generate InitialContext");
e.printStackTrace();
}
return null;
}
}
And after i start my JBoss server, I try to run the java code and I get this exception:
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at client.Test.getInitialContext(Test.java:32)
at client.Test.main(Test.java:13)
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
What might be the problem?