1 文件结构如下
--src
--com.ibeidou.generated.ejb
--MyHelloBean.java
--build.properties
--build.xml
2 stateless session bean
package com.ibeidou.generated.ejb;
import javax.ejb.*;
/*
*@ejb:bean type="Stateless" name="HelloWorldBean" jndi-name="ejb.helloworld"
* display-name="Hello ejb"
*/
public abstract class HelloWorldBean implements SessionBean {
private SessionContext sessionContext;
public void ejbCreate() throws CreateException {
}
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
}
}
3 build.properties
# xdoclet directory
xdoclet.home=E:/java/xdocletsample/xdoclet-1.2.3
# ant directory
ant.home=E:/soft/java/apache-ant-1.8.1
# ejb jar
jar.dir=E:/java/xdocletsample/ejb-jar
其中E:/java/xdocletsample/ejb-jar 目录中含有jboss-j2ee.jar这个jar包
E:/java/xdocletsample/xdoclet-1.2.3含有log4j.jar,及xdoclet所需的所有jar包
4 build.xml
<project name="xdocletejb" default="ejbdoclet" basedir=".">
<!--载入属性文件-->
<property file="build.properties"/>
<!-- 定义类路径 -->
<path id="myclasspath">
<pathelement path="${java.class.path}/" />
<fileset dir="${jar.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${xdoclet.home}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${ant.home}">
<include name="**/*.jar"/>
</fileset>
</path>
<!-- Init -->
<target name="init">
<property name="src.dir" value="src" />
<property name="build.dir" value="build" />
<property name="generated.src.dir" value="gen-src"></property>
</target>
<!-- Prepare -->
<target name="prepare" depends="init">
<mkdir dir="${build.dir}" />
<mkdir dir="${build.dir}/ejb" />
<mkdir dir="${build.dir}/ejb/META-INF" />
<mkdir dir="${build.dir}/classes" />
</target>
<!-- Run EJBDoclet -->
<target name="ejbdoclet" depends="prepare">
<taskdef name="ejbdoclet"
classname="xdoclet.modules.ejb.EjbDocletTask" classpathref="myclasspath" />
<ejbdoclet
destdir="${generated.src.dir}"
excludedtags="@version,@author"
ejbspec="2.0">
<fileset dir="${src.dir}">
<include name="**/HelloWorldBean.java" />
</fileset>
<remoteinterface/>
<homeinterface/>
<deploymentdescriptor destdir="${build.dir}/ejb/META-INF"/>
<jboss version="2.4" xmlencoding="UTF-8" destdir="${build.dir}/ejb/META-INF"/>
<weblogic xmlencoding="UTF-8" destdir="${build.dir}/ejb/META-INF" validatexml="true"/>
<webSphere destdir="${build.dir}/ejb/META-INF" />
<orion destdir="${build.dir}/ejb/META-INF" />
</ejbdoclet>
</project>
在根目录下ant即可自动生成remote和home接口。