基于Tomcat的自动构建和发布

<project name="app" default="all" basedir=".">

 <property file="${basedir}/build.properties" />
 <!-- set global properties for this build -->
 <property name="app.project.root" value="kmss_hr_pm" />
 <property name="app.project.name" value="kpi" />
 <property name="app.src"
  value="${app.project.name}/${app.project.root}/src" />
 <property name="app.web"
  value="${app.project.name}/${app.project.root}/WebContent" />
 <property name="build" value="${app.web}/WEB-INF/classes" />
 <property name="dist" value="dist" />
 <property name="cvsroot"
  value=":pserver:${cvs.user}:${cvs.password}@${cvs.server}:${cvs.repository}" />

 <property name="main.dir" value="${app.project.name}" />
 <property name="main.cvs.repository.path"
  value="${app.project.root}" />
 <property name="tomcat.home"
  value="D:/Apache Software Foundation/Tomcat 5.0" />
 <!--
  Initializing -->
 <target name="init">
  <tstamp>
   <format property="today" pattern="yyyy-MM-dd hh:mm:ss" />
  </tstamp>
  <echo message="${today}" />
   <echo message="*****************************************" />
   <echo message="         --应用程序自动发布--               " />
   <echo message="     系统将自动运行以下任务:            " />
   <echo message="     1.从cvs下载源代码                   " />
   <echo message="     2.编译下载的源代码                  " />
   <echo message="     3.停止tomcat程序运行                " />
   <echo message="     4.将编译好的应用程序打包            " />
   <echo message="     5.发布应用程序到tomcat应用服务器    " />
   <echo message="     6.启动tomcat应用服务器              " />
   <echo message="******************************************" />
   <sleep seconds="5"/>
 </target>
 <target name="all" depends="init,clean,main-check-out,compile,dist,deploy">
 </target>
 <!-- 捡出主干程序 -->
 <target name="main-check-out">
  <echo message="正在捡出程序..." />
  <cvs cvsRoot="${cvsroot}" package="${main.cvs.repository.path}"
   dest="${main.dir}" />
 </target>

 <target name="compile">
  <!-- Compile the java code from ${src} into ${build} -->
  <echo message="正在编译应用程序..." />
  <delete dir="${build}" />
  <mkdir dir="${build}" />
  <echo message="build src:${app.src}/ndestdir:${build}" />
  <javac srcdir="${app.src}" destdir="${build}" encoding="UTF-8"
   source="1.4" fork="true" memoryMaximumSize="512M">

   <classpath>
    <fileset dir="${basedir}">
     <include name="${app.web}/WEB-INF/lib/*.jar" />
     <include name="lib/*.jar" />
    </fileset>
    <pathelement path="${java.class.path}/" />
   </classpath>
  </javac>
  <copy toDir="${build}">
   <fileset dir="${app.src}"
    includes="**/*.properties,**/*.xml" />
  </copy>
 </target>

 <target name="dist">
  <echo message="正在构建程序到${dist}目录..." />
  <mkdir dir="${dist}" />
  <copy todir="${dist}">
   <fileset dir="${app.web}" />
  </copy>
 </target>

 <target name="clean">
  <echo message="正在清除${dist}中的历史构建..." />
  <delete dir="${dist}" />
  <delete dir="${app.project.root}" />
 </target>
 <target name="deploy"
  depends="stop-tomcat,delete-old-work,create-war-file,start-tomcat" >
  <echo message="发布应用程序完毕." />
 </target>
 <target name="start-tomcat">
  <echo message="正在启动tomcat..." />
  <exec dir="${tomcat.home}/bin"
   executable="${tomcat.home}/bin/startup.bat"
   spawn="true">
  </exec>
 </target>
 <target name="stop-tomcat">
  <echo message="正在停止tomcat..." />
  <exec dir="${tomcat.home}/bin"
   executable="${tomcat.home}/bin/shutdown.bat">
  </exec>
  <sleep seconds="6"/>
 </target>
 <target name="delete-old-work">
  <echo message="正在清除tomcat中的历史发布..." />
  <delete dir="${tomcat.home}/work/Catalina/localhost" failοnerrοr="false"/>
  <delete dir="${tomcat.home}/webapps/kpi"  failοnerrοr="false"/>
  <delete file="${tomcat.home}/webapps/kpi.war"  failοnerrοr="false"/>
 </target>
 <target name="create-war-file">
  <echo message="正在打包应用程序..." />
  <war destfile="${tomcat.home}/webapps/kpi.war"
   basedir="${dist}" webxml="${dist}/WEB-INF/web.xml">
  </war>
 </target>
</project>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值