将Hello.jar加入到Apusic Application Server配置文件中。在/usr/apusic/config/server.xml 加入以下几行:
<module>
<EJB>
<EJB-uri>classes/Hello.jar
</EJB-uri>
<bean>
<EJB-name>Hello</EJB-name>
<jndi-name>HelloHome
</jndi-name>
</bean>
</EJB>
</module>
启动服务器
java -Xms64m com.apusic.server.Main -root /usr/apusic
7、写客户端调用程序
您可以从Java Client,JSP,Servlet或别的EJB调用HelloBean。
调用EJB有以下几个步骤:
通过JNDI(Java Naming Directory Interface)得到EJB Home Interface
通过EJB Home Interface 创建EJB对象,并得到其Remote Interface
通过Remote Interface调用EJB方法
以下是一个从Java Client中调用HelloBean的例子:
package EJB.hello;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;
import javax.EJB.*;
import java.rmi.RemoteException;
/**
* @author Copyright (c) 2000 by Apusic,
Inc. All Rights Reserved.
*/
public class HelloClient{
public static void main(String args[])
{
String url = "rmi://localhost:6888";
Context initCtx = null;
HelloHome hellohome = null; try{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.apusic.jndi.InitialContextFactory");
env.put(Context.PROVIDER_URL, url);
initCtx = new InitialContext(env);
}catch(Exception e){
System.out.println("Cannot get initial
context: " + e.getMessage());
System.exit(1);
}
try{
hellohome =
(HelloHome)initCtx.lookup("HelloHome");
Hello hello = hellohome.create();
String s = hello.getHello();
System.out.println(s);
}catch(Exception e){
System.out.println(e.getMessage());
System.exit(1);
}
}
}
运行HelloClient,可得到以下输出:
Hello World
