错误信息如下:
[code="java"]
18:04:02,358 ERROR [STDERR] javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory ]
18:04:02,359 ERROR [STDERR] at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
18:04:02,359 ERROR [STDERR] at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
18:04:02,359 ERROR [STDERR] at javax.naming.InitialContext.init(Unknown Source)
18:04:02,359 ERROR [STDERR] at javax.naming.InitialContext.(Unknown Source)
18:04:02,359 ERROR [STDERR] at servlet.SampleServlet.initBean(SampleServlet.java:92)
[/code]
出现错误的代码如下:
[code="java"]
package servlet;
......
public class SampleServlet extends HttpServlet{
......
private void initBean()throws ServletException{
try{
Properties properties = new Properties();
//这里报错
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory ");
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces ");
properties.setProperty(Context.PROVIDER_URL, "localhost:1099");
initialContext = new InitialContext(properties);
Object objref = initialContext.lookup("security-sample/UserManagement");
Object obj = PortableRemoteObject.narrow(objref,UserManagementHome.class);
home = (UserManagementHome)obj;
bean = home.create();
}
catch (CreateException e1) {
e1.printStackTrace();
throw new ServletException(e1.getMessage());
}
catch(NamingException ne){
ne.printStackTrace();
throw new ServletException(ne.getMessage());
}
catch (RemoteException e) {
e.printStackTrace();
}
}
......
}
[/code]
在网上找了各种方法,都试过了,都不好使。
1、把javaall-client.jar、jnp-client.jar文件放到Java Build Path里
2、classpath里加%JBoss Home%\client\jbossall-client.jar
都不好使,希望高手能给予帮助