编写过程不说,只说部署与调用,下面这三段代码已经很能说明问题。
1、ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC ''-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN'' ''" target=_blank>http://java.sun.com/dtd/ejb-jar_2_0.dtd''>
<!-- Generated XML! -->
<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专署配置文件)
<!DOCTYPE weblogic-ejb-jar PUBLIC ''-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN'' ''" target=_blank>http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd''>
<!-- Generated XML! -->
<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(客户端代码,最好和四个接口一起打包)
/*
* Created on 2004-5-11
*/
package org.bromon.ejb.session;
import javax.naming.*;
import javax.rmi.*;
import java.util.*;
/**
* @author Bromon
*/
public class HelloClient
{
public static void main(String args[])
{
try
{
Properties prop=new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");//加载weblogic上下文环境
prop.put(Context.PROVIDER_URL,"t3://localhost:7001");//weblogic专用协议
Context ctx=new InitialContext(prop);
Object obj=ctx.lookup("Hello");
HelloHome home=(HelloHome)PortableRemoteObject.narrow(obj,HelloHome.class);
Hello hello=home.create();
System.out.println(hello.say());
hello.remove();
}catch(Exception e)
{
System.out.println(e);
}
}
}