jboss 部署成功了 但客户端调用出现问题
报错:
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interf
aces.Naming ContextFactory [Root exception is java.lang.ClassNotFoundException:
org/jnp/interfaces/Naming ContextFactory]
客户端:
package greet;
import javax.naming.*;
import java.util.Hashtable;
import javax.rmi.PortableRemoteObject;
import greet.*;
class GreetClient
{
public static void main(String[] args) {
System.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.Naming ContextFactory");
System.setProperty("java.naming.provider.url",
"localhost:1099");
try {
// Get a naming context
InitialContext jndiContext = new InitialContext();
System.out.println("Got context");
Object ref = jndiContext.lookup("GreetingEJB");
System.out.println("Got reference");
GreetHome home = (GreetHome)
PortableRemoteObject.narrow (ref, GreetHome.class);
Greet greet = home.create();
System.out.print("The magic number from server is ");
System.out.println(greet.calculateMagic(123.456));
} catch(Exception e) {
System.out.println(e.toString());
}
}
}
ejb-jar.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<description>jBoss test application </description>
<display-name>Test</display-name>
<enterprise-beans>
<session>
<ejb-name>GreetEJB</ejb-name>
<home>greet.GreetHome</home>
<remote>greet.Greet</remote>
<ejb-class>greet.GreetBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
jboss.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<jboss>
<enterprise-beans>
<session>
<ejb-name>GreetEJB</ejb-name>
<jndi-name>GreetingEJB</jndi-name>
</session>
<secure>false</secure>
</enterprise-beans>
<resource-managers/>
</jboss>
------解决方法--------------------------------------------------------
/deploy.lib/jnpserver.jar包加入classpath就能解决这个问题.