如何调用weblogic8.1下EJB的部署?
如何调用weblogic8.1下EJB的部署?
EJB编写不容易,部署起来也不简单啊,不同的平台不同的容器不同的部署工具,头都整昏了。weblogic这东西牛,值得研究,拿它开刀。编写过程不说,只说部署与调用,下面这三段代码已经很能说明问题。
1、ejb-jar.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEejb-jarPUBLIC''-//SunMicrosystems,Inc.//DTDEnterpriseJavaBeans2.0//EN''''" target=_blank>http://java.sun.com/dtd/ejb-jar_2_0.dtd''>
<!--GeneratedXML!-->
<ejb-jar>
<display-name>hello</display-name>
<enterprise-beans>
<session>
<display-name>HelloBean</display-name>
<ejb-name>Hello</ejb-name>
<home>org.bromon.ejb.session.HelloHome</home>
<remote>org.bromon.ejb.session.Hello</remote>
<local-home>org.bromon.ejb.session.HelloLocalHome</local-home>
<local>org.bromon.ejb.session.HelloLocal</local>
<ejb-class>org.bromon.ejb.session.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
<security-identity>
<use-caller-identity/>
</security-identity>
</session>
</enterprise-beans>
</ejb-jar>
2、weblogic-ejb-jar.xml(weblogic专署配置文件)
<!DOCTYPEweblogic-ejb-jarPUBLIC''-//BEASystems,Inc.//DTDWebLogic8.1.0EJB//EN''''" target=_blank>http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd''>
<!--GeneratedXML!-->
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>Hello</ejb-name>
<stateless-session-descriptor>
<pool>
</pool>
<stateless-clustering>
</stateless-clustering>
</stateless-session-descriptor>
<transaction-descriptor>
</transaction-descriptor>
<jndi-name>Hello</jndi-name>
<local-jndi-name>HelloLocal</local-jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
3、HelloClient.java(客户端代码,最好和四个接口一起打包)
/*
*Createdon2004-5-11
*/
packageorg.bromon.ejb.session;
importjavax.naming.*;
importjavax.rmi.*;
importjava.util.*;
/**
*@authorBromon
*/
publicclassHelloClient
{
publicstaticvoidmain(Stringargs[])
{
try
{
Propertiesprop=newProperties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");//加载weblogic上下文环境
prop.put(Context.PROVIDER_URL,"t3://localhost:7001");//weblogic专用协议
Contextctx=newInitialContext(prop);
Objectobj=ctx.lookup("Hello");
HelloHomehome=(HelloHome)PortableRemoteObject.narrow(obj,HelloHome.class);
Hellohello=home.create();
System.out.println(hello.say());
hello.remove();
}catch(Exceptione)
{
System.out.println(e);
}
}
}