全自动的使用ANT编译,打包EJB项目,并且部署到Websphere服务器上面
2009-09-16 22:54
946 查看
全自动的使用ANT编译,打包EJB项目,并且部署到Websphere服务器上面。 收藏
全自动的使用ANT编译,打包EJB项目,并且部署到Websphere服务器上面。题外话,刚发现J***AEYE没有EJB和WebSphere的板块,有点小郁闷。
首先我们可以在build.properties上面定义在编译部署过程中使用到的变量。
包括项目名,项目路径,部署路径等等
Xml代码
app.name=XXXXX
dist.home=C:/antoutput
encoding=UTF-8
project.home=C:/CVSROOT/src/XXXXX
deploy.path=C:/Program Files/IBM/SDP70/runtimes/base_v61/profiles/AppSrvWSFP01/installedApps/D1N4GGBXNode02Cell
.
.
.
.
然后是项目的CLASS_PATH。
Xml代码
project.class.path=
XXX1_LIB=XXXXXXXX1
XXX2_LIB=XXXXXXXX2
XXX1_LIB.dir=${project.home}/${XXX1_LIB}
XXX2_LIB.dir=${project.home}/${XXX2_LIB}
然后是Websphere相关的Lib的路径
Xml代码
websphere.base_v61.runtime.dir=C:/Program Files/ibm/SDP70/runtimes/base_v61
websphere.runtime.lib.dir=${websphere.base_v61.runtime.dir}/lib
websphere.runtime.plugins.lib.dir=${websphere.base_v61.runtime.dir}/plugins
websphere.runtimes.webservice.lib.dir=${websphere.base_v61.runtime.dir}/runtimes
在这些变量设置好了之后,我们就可以开始编译了。
在build.xml里面,
引用build.properties里面设置好的变量。
Xml代码
<property file="build.properties" />
设置CLASS_PATH
Xml代码
<path id="XXX1_LIB.classpath">
<fileset dir="${XXX1_LIB.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<path id="XXX2_LIB.classpath">
<fileset dir="${XXX2_LIB.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<path id="project.class.path">
<pathelement path="${project.class.path}" />
</path>
<path id="websphere.runtime.classpath">
<fileset dir="${websphere.runtime.lib.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${websphere.runtime.plugins.lib.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${websphere.runtimes.webservice.lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
然后进行必要的文件目录的初始化。
Xml代码
<target name="clean">
<delete dir="${dist.home}" />
.
.
.
.
</target>
<target name="init">
<mkdir dir="${dist.home}" />
.
.
.
.
.
</target>
从cvs上面下载更新代码
Xml代码
<target name="deleteCvsHome">
<delete dir="C:/cvstest" />
</target>
<target name="cvsCheckout">
<mkdir dir="C:/cvstest" />
<property name="cvsroot" value=":pserver:user:passwd@IP:/cvsroot/data/XXX" />
<property name="projectName" value="XXXXXXXXXXX" />
<tstamp>
<format property="today" pattern="yyyy-MM-dd hh:mm:ss" />
</tstamp>
<echo message="${today}" />
<cvs cvsRoot="${cvsroot}" dest="C:/cvstest" package="${projectName}" />
</target>
<target name="cvsUpdate">
<property name="cvsroot" value=":pserver:user:passwd@IP:/cvsroot/data/XXX" />
<property name="projectName" value="XXXXXXXXXXX" />
<tstamp>
<format property="today" pattern="yyyy-MM-dd hh:mm:ss" />
</tstamp>
<echo message="${today}" />
<cvs cvsRoot="${cvsroot}" command="update" dest="C:/cvstest" package="${projectName}" />
</target>
编译,注意配置好项目目的依赖关系就好了
Xml代码
<target name="buildxxxxDto" depends="init">
<mkdir dir="${xxxx.dto.classes}" />
<javac srcdir="${xxxx.dto.src}" destdir="${xxxx.dto.classes}" encoding="${encoding}" debug="true" deprecation="true" nowarn="false">
<classpath refid="project.class.path" />
<classpath refid="websphere.runtime.classpath" />
<classpath refid="XXX1_LIB.classpath" />
<classpath refid="XXX2_LIB.classpath" />
</javac>
</target>
<target name="buildxxxxEjbClient" depends="init,buildxxxxDto">
<mkdir dir="${xxxx.ejbclient.classes}" />
<javac srcdir="${xxxx.ejbclient.src}" destdir="${xxxx.ejbclient.classes}" encoding="${encoding}" debug="true" deprecation="true" nowarn="false">
<classpath refid="project.class.path" />
<classpath refid="websphere.runtime.classpath" />
<classpath refid="XXX1_LIB.classpath" />
<classpath refid="XXX2_LIB.classpath" />
</javac>
<copy todir="${xxxx.ejbclient.classes}">
<fileset dir="${xxxx.ejbclient.resources}">
<include name="**/*.properties" />
<include name="**/*.xml" />
</fileset>
</copy>
</target>
<target name="buildxxxxEjb" depends="init,buildxxxxDto,buildxxxxEjbClient">
<mkdir dir="${xxxx.ejb.classes}" />
<javac srcdir="${xxxx.ejb.src}" destdir="${xxxx.ejb.classes}" encoding="${encoding}" debug="true" deprecation="true" nowarn="false">
<classpath refid="project.class.path" />
<classpath refid="websphere.runtime.classpath" />
<classpath refid="XXX1_LIB.classpath" />
<classpath refid="XXX2_LIB.classpath" />
</javac>
</target>
<target name="buildxxxxSrvBizImpl" depends="init,buildxxxxEjbClient">
<mkdir dir="${xxxx.srv.classes}" />
<javac srcdir="${xxxx.srv.src}" destdir="${xxxx.srv.classes}" encoding="${encoding}" debug="true" deprecation="true" nowarn="false">
<classpath refid="project.class.path" />
<classpath refid="websphere.runtime.classpath" />
<classpath refid="XXX1_LIB.classpath" />
<classpath refid="XXX2_LIB.classpath" />
</javac>
<copy todir="${xxxx.srv.classes}">
<fileset dir="${xxxx.srv.resources}">
<include name="**/*.properties" />
<include name="**/*.xml" />
</fileset>
</copy>
</target>
<target name="buildxxxxweb" depends="init,buildxxxxEjbClient">
<mkdir dir="${xxxx.web.classes}" />
<javac srcdir="${xxxx.web.src}" destdir="${xxxx.web.classes}" encoding="${encoding}" debug="true" deprecation="true" nowarn="false">
<classpath refid="project.class.path" />
<classpath refid="websphere.runtime.classpath" />
<classpath refid="XXX1_LIB.classpath" />
<classpath refid="XXX2_LIB.classpath" />
</javac>
<copy todir="${xxxx.web.classes}">
<fileset dir="${xxxx.web.resources}">
<include name="**/*.properties" />
<include name="**/*.xml" />
</fileset>
</copy>
<copy todir="${xxxx.web.content}">
<fileset dir="${project.home}/xxxx_WEB/WebContent">
<exclude name="WEB-INF/classes/**/*.*" />
</fileset>
</copy>
</target>
打包
Xml代码
<target name="jarxxxxDto" depends="buildxxxxDto">
<jar destfile="${dist.home}/XXXXXXXXXX/xxxx_SrvDTO.jar"
basedir="${xxxx.dto.classes}"
manifest="${xxxx.dto.src}/META-INF/MANIFEST.MF">
<fileset dir="${xxxx.dto.src}">
<include name="**/*.java" />
</fileset>
</jar>
</target>
<target name="jarxxxxsrv" depends="buildxxxxSrvBizImpl">
<jar destfile="${dist.home}/XXXXXXXXXX/xxxx_SrvBizImpl.jar"
basedir="${xxxx.srv.classes}"
manifest="${xxxx.srv.src}/META-INF/MANIFEST.MF">
<fileset dir="${xxxx.srv.src}">
<include name="**/*.java" />
</fileset>
</jar>
</target>
<target name="jarxxxxejb" depends="buildxxxxEjb">
<jar destfile="${dist.home}/XXXXXXXXXX/xxxx_EJB.jar"
basedir="${xxxx.ejb.classes}"
manifest="${xxxx.ejb.src}/META-INF/MANIFEST.MF">
<metainf dir="${xxxx.ejb.src}/META-INF">
<include name="**/*.*" />
</metainf>
<fileset dir="${xxxx.ejb.src}">
<include name="**/*.java" />
</fileset>
</jar>
</target>
<target name="jarxxxxejbclient" depends="buildxxxxEjbClient">
<jar destfile="${dist.home}/XXXXXXXXXX/xxxx_EJB_Client.jar"
basedir="${xxxx.ejbclient.classes}"
manifest="${xxxx.ejbclient.src}/META-INF/MANIFEST.MF">
<fileset dir="${xxxx.ejbclient.src}">
<include name="**/*.java" />
</fileset>
</jar>
</target>
然后把打好的jar包还有web项目的文件都放到同一个目录的正确的位置,准备打成ear包
Xml代码
<target name="forEar" depends="clean,init,buildAll,jarAll">
<copy todir="${dist.home}/XXXXXXXXXX">
<fileset dir="${jcm.ear}">
<include name="**/*.properties" />
<include name="**/*.xml" />
<include name="**/*.MF" />
<include name="**/*.dtd" />
<include name="**/.compatibility" />
<exclude name=".settings/**/*.*" />
</fileset>
<fileset dir="${dist.home}">
<include name="xxxx_WEB.war/**/*.*" />
</fileset>
<fileset dir="${XXX1_LIB.dir}">
<include name="asm-2.2.1.jar" />
.
.
.
.
.
</fileset>
<fileset dir="${XXX2_LIB.dir}">
<include name="log4j-1.2.14.jar" />
.
.
.
.
.
</fileset>
</copy>
</target>
打ear包
Xml代码
<target name="createEar" depends="forEar">
<delete dir="${dist.home}/XXXXXXXXXX/temp" />
<delete dir="${dist.home}/temp" />
<mkdir dir="${dist.home}/XXXXXXXXXX/temp" />
<mkdir dir="${dist.home}/temp" />
<war destfile="${dist.home}/XXXXXXXXXX/temp/xxxx_WEB.war" webxml="${dist.home}/XXXXXXXXXX/xxxx_WEB.war/WEB-INF/web.xml">
<fileset dir="${dist.home}/XXXXXXXXXX/xxxx_WEB.war/">
<include name="**/*.*" />
<exclude name="WEB-INF/web.xml" />
</fileset>
</war>
<ear destfile="${dist.home}/temp/XXXXXXXXXX" appxml="${dist.home}/XXXXXXXXXX/META-INF/application.xml">
<fileset dir="${dist.home}/XXXXXXXXXX">
<include name="**/*.jar" />
<include name="**/*.xml" />
<include name="**/*.properties" />
<include name="**/*.xsl" />
<exclude name="xxxx_WEB.war/**/*.*" />
<exclude name="**/application.xml" />
</fileset>
<fileset dir="${dist.home}/XXXXXXXXXX/temp">
<include name="*.war" />
</fileset>
</ear>
</target>
然后就需要部署到websphere服务器上面去了。
先要利用websphere的部署工具生成服务器的部署代码
Xml代码
<target name="ForDeploy">
<exec dir="C:/Program Files/IBM/SDP70/runtimes/base_v61/bin" executable="cmd">
<arg line="/c ejbdeploy.bat -complianceLevel 5.0 C:/antoutput/temp/XXXXXXX.ear C:/antoutput/temp C:/anttest/XXXXXXXX.ear" />
</exec>
</target>
这个完成了之后,我们就得到了一个可以直接部署到服务器上面的ear文件
然后,我们可以利用websphere提供的命令完成很多的工作。
停止服务器
Xml代码
<target name="stopServer">
<exec dir="C:/Program Files/IBM/SDP70/runtimes/base_v61/bin" executable="cmd">
<arg line="/c stopServer.bat server1 -profileName AppSrv01" />
</exec>
</target>
启动服务器
Java代码
<target name="startServer">
<exec dir="C:/Program Files/IBM/SDP70/runtimes/base_v61/bin" executable="cmd">
<arg line="/c startServer.bat server1 -profileName AppSrv01" />
</exec>
</target>
部署EAR
Xml代码
<target name="installEar">
<exec dir="C:/Program Files/IBM/SDP70/runtimes/base_v61/bin" executable="cmd">
<arg line="/c wsadmin.bat -process server1 -profileName AppSrvWSFP01 -f reDeploy.jacl" />
</exec>
</target>
reDeploy.jacl
Xml代码
#这是我们要发布的应用的存放路径
set EARDIR C:/antoutput/temp/XXXXX.ear
#这是我们要发布的应用的名称
set APPNAME XXXXX
set NODE [$AdminControl getNode]
puts "-- stoping App --"
set APPMANAGER [$AdminControl queryNames type=ApplicationManager,node=D1N4GGBXNode02,process=server1,*]
$AdminControl invoke $APPMANAGER stopApplication XXXXX
puts "-- stoped App --"
puts "-- uninstalling App --"
$AdminApp uninstall XXXXX
puts "-- uninstalled App --"
puts "-- saveing config --"
$AdminConfig save
puts "-- saved config --"
puts "-- Installing App --"
$AdminApp install $EARDIR {-appname XXXXX}
puts "-- Installed App --"
puts "-- saveing config --"
$AdminConfig save
puts "-- saved config --"
puts "-- starting app --"
set APPMANAGER [$AdminControl queryNames type=ApplicationManager,node=D1N4GGBXNode02,process=server1,*]
$AdminControl invoke $APPMANAGER startApplication XXXXX
puts "-- started app --"
这样的一套ant文件和jacl文件完成以后,我们就可以设定为定时任务。然后服务器就可以每天定时进行自动部署了。
当然,其实在部署的时候,如果你的项目还在BUG修正的时期,可能需要修改了bug然后到测试环境很快的验证一下,上面的工作全部都做完大概要花上30分钟,很不划算,我们可以
跳过打EAR包的过程,直接将编译后的文件和相关的修改过jar包COPY到部署后的目录,重启服务器就好了,这个也可以做成target,稍微修改一下上面的ant代码,省略几个步骤
就可以了。
相关文章推荐
- 使用Ant给EJB项目编译、打包、发布
- 使用ant编译打包、部署简单的javaweb项目 --01
- 使用ant编译打包、部署简单的javaweb项目 --02
- 使用Ant构建web项目 从编译到测试 生成测试报告 打包 邮件发送 远程下载tomcat 部署运行一条龙服务之ant脚本
- 使用ant脚本,对java web项目,编译、打包、发布部署到tomcat
- 使用ant脚本,对java web项目,编译、打包、发布部署到tomcat
- 在Hudson中,使用ant自动对安卓项目编译打包apk
- Android App自动化之使用Ant编译项目多渠道打包
- Ant自动编译打包android项目(二)----签名与渠道包
- 使用WSAdmin和ANT自动部署websphere6.1
- Ant + SvnLib实现自动更新,编译,打包,发布部署
- Hudson之——Hudson的使用(使用 Hudson 来自动化编译、分析、打包、发布、部署项目)
- Ant自动编译打包&发布 android项目
- 用Ant实现Java项目的自动构建和部署/Eclipse下使用Ant
- Android 自动编译、打包生成apk文件 2 - 使用原生Ant方式
- App自动化之使用Ant编译项目多渠道打包
- Android项目使用Ant打包,自动生成build.xml
- Android笔记之:App自动化之使用Ant编译项目多渠道打包的使用详解
- Ant自动编译打包android项目
- 使用ANT编译--实现外部传参(多渠道替换)、批处理打包------第二步什么是ANT,如何使用ANT命令为Android项目打包