myeclipse+weblogic开发ejb2.x
package client;import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
public class EjbFactory {
public static Object getEjbHome(String jndiName) throws Exception{
//连接到WebLogic
Properties pro = new Properties();
pro.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
pro.put(Context.PROVIDER_URL,"t3://localhost:7001");//指定了Weblogic服务器的名称(IP),远程调用体现在这里
pro.put(Context.SECURITY_PRINCIPAL,"weblogic");
pro.put(Context.SECURITY_CREDENTIALS,"weblogic");
Context context = new InitialContext(pro);
Object obj = context.lookup(jndiName);//根据JNDI名称查找,查找到就是home接口
return obj;
}
}
package client;
import javax.rmi.PortableRemoteObject;
import prj30_1.ConvertEjbHome;
import prj30_1.ConvertEjb;
public class Client1 {
public static void main(String args[]) throws Exception{
Object obj = EjbFactory.getEjbHome("ConvertEjb");
ConvertEjbHome home = (ConvertEjbHome)PortableRemoteObject.narrow(obj,ConvertEjbHome.class);
ConvertEjb remote = home.create();
double rmb = remote.getValue();
System.out.println("连接成功");
}
}
这时客户端调用时连接的服务器的代码 其他的和Jboss相似
weblogic在eclipse的配置方法见本人的服务器中的myeclipse中如何配置weblogic
页:
[1]