javax.naming.NoInitialContextException: Cannot instantiate class:

流过昼夜 提交于 2019-12-10 12:06:43

问题


I'm trying to implement Simple EJB Application Described in tutorialpoint and I’m using JBoss 5.1 and eclipse as IDE and i created project as EJB 3. but I’m getting the below error

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(NamingManager.java:674)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
at com.tutorialspoint.test.EJBTester.<init>(EJBTester.java:42)
at com.tutorialspoint.test.EJBTester.main(EJBTester.java:51)
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:72)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:61)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:671)
... 5 more
java.lang.NullPointerException
at com.tutorialspoint.test.EJBTester.testStatelessEjb(EJBTester.java:65)
at com.tutorialspoint.test.EJBTester.main(EJBTester.java:53)
null

can anyone Guide me on this?


回答1:


You need to add a jar with class org.jnp.interfaces.NamingContextFactory to the classpath in your client code.

You can get it here. Make sure to get the appropriate jar for jboss 5.x if you get a version mismatch error.



来源:https://stackoverflow.com/questions/32901871/javax-naming-noinitialcontextexception-cannot-instantiate-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!