}
public void ejbPassivate() throws EJBException, RemoteException {
System.out.println("ejbPassivate");
}
public String example()
{
System.out.println("example()");
return "Just a simple example!";
}
}
客户端调用程序文件:ExampleClient.java
package examples;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.util.Properties;
public class ExampleClient {
public ExampleClient() {
super();
}
public static void main(String[] args){
try{
Properties props =new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
props.put(Context.PROVIDER_URL,"172.16.1.4:1099");
Context ctx = new InitialContext(props);
System.out.println("start ejb client test");
Object obj=ctx.lookup("Example");
ExampleHome home = (ExampleHome)PortableRemoteObject.narrow(obj,ExampleHome.class);
Example example = home.create();
System.out.println(example.example());
example.remove();
}catch(Exception e)
{
e.printStackTrace();
}
}
}
EJB打包
我们需要将以上文件编译的CLASS文件打成一个JAR包,部署到JBOSS中,才能调用






