dingwm
发贴: 7
积分: 0
|
于 2005-05-07 12:22
MYECLIPSE+JBOSS4 写了个EJB 测试时遇到问题 请各位大侠看看 客户端代码: /* * Created on 2005-5-6 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package com.bjb.helloworld.test; import javax.naming.Context; import javax.naming.InitialContext; import com.bjb.helloworld.ejb.*; import com.bjb.helloworld.interfaces.*; import javax.rmi.PortableRemoteObject; import java.util.*; import org.jnp.interfaces.NamingContextFactory; /** * @author cclx * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class HelloTestClient {
public static void main(String[] args) throws Exception { Context ctx=getInitialContext(); Object obj=ctx.lookup(HelloWorldHome.JNDI_NAME); HelloWorldHome helloworldhome=(HelloWorldHome)PortableRemoteObject.narrow (obj,HelloWorldHome.class); HelloWorld helloworld=helloworldhome.create(); System.out.println(helloworld.helloWorld()); } private static Context getInitialContext() throws Exception{ String url="t3://127.0.0.1:7001"; String user="cclx"; String password="cclx"; Properties properties=null; properties=new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); properties.put(Context.PROVIDER_URL,url); if(user!=null){ properties.put(Context.SECURITY_PRINCIPAL,user); properties.put(Context.SECURITY_CREDENTIALS, password==null? "" : password); } return new InitialContext(properties); } }
错误 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:652) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243) at javax.naming.InitialContext.init(InitialContext.java:219) at javax.naming.InitialContext.<init>(InitialContext.java:195) at com.bjb.helloworld.test.HelloTestClient.getInitialContext(HelloTestClient.java:45) at com.bjb.helloworld.test.HelloTestClient.main(HelloTestClient.java:23) Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:199) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:187) at java.lang.ClassLoader.loadClass(ClassLoader.java:289) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274) at java.lang.ClassLoader.loadClass(ClassLoader.java:235) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:219) at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42) at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649) ... 5 more Exception in thread "main"
|