现在的位置: 首页 > 综合 > 正文

全自动的使用ANT编译,打包EJB项目,并且部署到Websphere服务器上面。

2013年04月18日 ⁄ 综合 ⁄ 共 5477字 ⁄ 字号 评论关闭
 

全自动的使用ANT编译,打包EJB项目,并且部署到Websphere服务器上面。

题外话,刚发现JAVAEYE没有EJB和WebSphere的板块,有点小郁闷。

首先我们可以在build.properties上面定义在编译部署过程中使用到的变量。

包括项目名,项目路径,部署路径等等

Xml代码 复制代码
  1. app.name=XXXXX  
  2. dist.home=C:/antoutput   
  3. encoding=UTF-8   
  4. project.home=C:/CVSROOT/src/XXXXX   
  5. deploy.path=C:/Program Files/IBM/SDP70/runtimes/base_v61/profiles/AppSrvWSFP01/installedApps/D1N4GGBXNode02Cell   
  6.   
  7. .   
  8. .   
  9. .   
  10. .  

然后是项目的CLASS_PATH。

Xml代码 复制代码
  1. project.class.path=   
  2.   
  3. XXX1_LIB=XXXXXXXX1   
  4. XXX2_LIB=XXXXXXXX2  
  5. XXX1_LIB.dir=${project.home}/${XXX1_LIB}   
  6. XXX2_LIB.dir=${project.home}/${XXX2_LIB}  

然后是Websphere相关的Lib的路径

Xml代码 复制代码
  1. websphere.base_v61.runtime.dir=C:/Program Files/ibm/SDP70/runtimes/base_v61   
  2.   
  3. websphere.runtime.lib.dir=${websphere.base_v61.runtime.dir}/lib   
  4. websphere.runtime.plugins.lib.dir=${websphere.base_v61.runtime.dir}/plugins   
  5. websphere.runtimes.webservice.lib.dir=${websphere.base_v61.runtime.dir}/runtimes  

在这些变量设置好了之后,我们就可以开始编译了。

在build.xml里面,

引用build.properties里面设置好的变量。

Xml代码 复制代码
  1. <property file="build.properties" />  

设置CLASS_PATH

Xml代码 复制代码
  1. <path id="XXX1_LIB.classpath">  
  2.     <fileset dir="${XXX1_LIB.dir}">  
  3.         <include name="**/*.jar" />  
  4.     </fileset>  
  5. </path>  
  6. <path id="XXX2_LIB.classpath">  
  7.     <fileset dir="${XXX2_LIB.dir}">  
  8.         <include name="**/*.jar" />  
  9.     </fileset>  
  10. </path>  
  11. <path id="project.class.path">  
  12.     <pathelement path="${project.class.path}" />  
  13. </path>  
  14. <path id="websphere.runtime.classpath">  
  15.     <fileset dir="${websphere.runtime.lib.dir}">  
  16.         <include name="**/*.jar" />  
  17.     </fileset>  
  18.     <fileset dir="${websphere.runtime.plugins.lib.dir}">  
  19.         <include name="**/*.jar" />  
  20.     </fileset>  
  21.     <fileset dir="${websphere.runtimes.webservice.lib.dir}">  
  22.         <include name="**/*.jar" />  
  23.     </fileset>  
  24. </path>  

然后进行必要的文件目录的初始化。

Xml代码 复制代码
  1. <target name="clean">  
  2.     <delete dir="${dist.home}" />  
  3.     .   
  4.     .   
  5.     .   
  6.     .   
  7.        
  8. </target>  
  9. <target name="init">  
  10.     <mkdir dir="${dist.home}" />  
  11.     .   
  12.     .   
  13.     .   
  14.     .   
  15.     .   
  16. </target>  

从cvs上面下载更新代码

Xml代码 复制代码
  1.    <target name="deleteCvsHome">  
  2.     <delete dir="C:/cvstest" />  
  3. </target>  
  4. <target name="cvsCheckout">  
  5.     <mkdir dir="C:/cvstest" />  
  6.     <property name="cvsroot" value=":pserver:user:passwd@IP:/cvsroot/data/XXX" />  
  7.     <property name="projectName" value="XXXXXXXXXXX" />  
  8.     <tstamp>  
  9.         <format property="today" pattern="yyyy-MM-dd hh:mm:ss" />  
  10.     </tstamp>  
  11.     <echo message="${today}" />  
  12.     <cvs cvsRoot="${cvsroot}" dest="C:/cvstest" package="${projectName}" />  
  13. </target>  
  14. <target name="cvsUpdate">  
  15.        <property name="cvsroot" value=":pserver:user:passwd@IP:/cvsroot/data/XXX" />  
  16.        <property name="projectName" value="XXXXXXXXXXX" />  
  17.        <tstamp>  
  18.            <format property="today" pattern="yyyy-MM-dd hh:mm:ss" />  
  19.        </tstamp>  
  20.     <echo message="${today}" />  
  21.     <cvs cvsRoot="${cvsroot}" command="update" dest="C:/cvstest" package="${projectName}" />  
  22. </target>  

编译,注意配置好项目目的依赖关系就好了

Xml代码 复制代码
  1. <target name="buildxxxxDto" depends="init">  
  2.     <mkdir dir="${xxxx.dto.classes}" />  
  3.     <javac srcdir="${xxxx.dto.src}" destdir="${xxxx.dto.classes}" encoding="${encoding}" debug="true" deprecation="true" nowarn="false">  
  4.         <classpath refid="project.class.path" />  
  5.         <classpath refid="websphere.runtime.classpath" />  
  6.         <classpath refid="XXX1_LIB.classpath" />  
  7.         <classpath refid="XXX2_LIB.classpath" />  
  8.     </javac>  
  9. </target>  
  10.   
  11.   
  12. <target name="buildxxxxEjbClient" depends="init,buildxxxxDto">  
  13.     <mkdir dir="${xxxx.ejbclient.classes}" />  
  14.     <javac srcdir="${xxxx.ejbclient.src}" destdir="${xxxx.ejbclient.classes}" encoding="${encoding}" debug="true" deprecation="true" nowarn="false">  
  15.         <classpath refid="project.class.path" />  
  16.         <classpath refid="websphere.runtime.classpath" />  
  17.         <classpath refid="XXX1_LIB.classpath" />  
  18.         <classpath refid="XXX2_LIB.classpath" />  
  19.     </javac>  
  20.     <copy todir="${xxxx.ejbclient.classes}">  
  21.         <fileset dir="${xxxx.ejbclient.resources}">  
  22.             <include name="**/*.properties" />  
  23.             <include name="**/*.xml" />  
  24.         </fileset>  
  25.     </copy>  
  26. </target>  
  27. <target name="buildxxxxEjb" depends="init,buildxxxxDto,buildxxxxEjbClient">  
  28.     <mkdir dir="${xxxx.ejb.classes}" />  
  29.     <javac srcdir="${xxxx.ejb.src}" destdir="${xxxx.ejb.classes}" encoding="${encoding}" debug="true" deprecation="true" nowarn="false">  
  30.         <classpath refid="project.class.path" />  
  31.         <classpath refid="websphere.runtime.classpath" />  
  32.         <classpath refid="XXX1_LIB.classpath" />  
  33.         <classpath refid="XXX2_LIB.classpath" />  
  34.     </javac>  
  35. </target>  
  36.   
  37. <target name="buildxxxxSrvBizImpl" depends="init,buildxxxxEjbClient">  
  38.     <mkdir dir="${xxxx.srv.classes}" />  
  39.     <javac srcdir="${xxxx.srv.src}" destdir="${xxxx.srv.classes}" encoding="${encoding}" debug="true" deprecation="true" nowarn="false">  
  40.         <classpath refid="project.class.path" />  
  41.         <classpath refid="websphere.runtime.classpath" />  
  42.         <classpath refid="XXX1_LIB.classpath" />  
  43.         <classpath refid="XXX2_LIB.classpath" />  
  44.     </javac>  
  45.     <copy todir="${xxxx.srv.classes}">  
  46.         <fileset dir="${xxxx.srv.resources}">  
  47.             <include name="**/*.properties" />  
  48.             <include name="**/*.xml" />  
  49.         </fileset>  
  50.     </copy>  
  51. </target>  
  52.   
  53. <target name="buildxxxxweb" depends="init,buildxxxxEjbClient">  
  54.     <mkdir dir="${xxxx.web.classes}" />  
  55.     <javac srcdir="${xxxx.web.src}" destdir="${xxxx.web.classes}" encoding="${encoding}" debug="true" deprecation

抱歉!评论已关闭.