binghai03 发表于 2017-1-29 06:04:35

通用ANT编译发布打包启动tomcat的模板

<?xml version="1.0" encoding="UTF-8"?>
<!--
======================================================================
2011-5-6 下午12:37:54description wu yifeng
======================================================================
-->
<project name="${project.name}" default="deploy" basedir=".">
<!--将name的值改为对应工程的名字将default的值改为需要的缺省任务-->
<!--
app.name 发布的应用名 app.version 版本 build.home 编译目标位置 appserver.home
tomcat根目录位置 deploy.home 部署位置 war.home war包位置 src.home src的位置
src.webroot WebRoot的位置
-->
<property file="build.properties" />
<property name="lib.home" value="${basedir}" />
<property environment="env" />
<property name="java.home" value="S{env.JAVA_HOME}" />
<property name="ant.home" value="S{env.ANT_HOME}" />
<!-- 路径设置 包括了jar文件才能编译-->
<path id="compile.classpath">
<fileset dir="${lib.home}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="test" description="description">
<echo message="project.name=${project.name}" />
<echo message="java.home=${java.home}" />
<echo message="ant.home=${ant.home}" />
<echo message="appserver.home=${appserver.home}" />
<echo message="deploy.path=${deploy.path}" />
<echo message="tomcat.manager.url=${tomcat.manager.url}" />
<echo message="tomcat.manager.username=${tomcat.manager.username}" />
<echo message="tomcat.manager.password=${tomcat.manager.password}" />
<echo message="build.home=${build.home}" />
<echo message="src.webroot=${src.webroot}" />
<echo message="build.web-inf=${build.web-inf}" />
<echo message="build.class=${build.class}" />
<echo message="build.lib=${build.lib}" />
<echo message="src.home=${src.home}" />
<echo message="src.res=${src.res}" />
<echo message="src.lib=${src.lib}" />
<echo message="src.web-inf=${src.web-inf}" />
<echo message="deploy.home=${deploy.home}" />
<echo message="cache.home=${cache.home}" />
</target>
<target name="clean" description="description">
<delete dir="${deploy.home}" failonerror="false" />
<delete dir="${build.home}" failonerror="false" />
<delete file="${deploy.path}/${project.name}.war" failonerror="false" />
</target>
<target name="init" depends="clean">
<mkdir dir="${build.home}" />
<mkdir dir="${build.web-inf}" />
<mkdir dir="${build.class}" />
<mkdir dir="${build.lib}" />
</target>
<target name="prepare" depends="init">
<copy todir="${build.home}">
<fileset dir="${src.webroot}" />
</copy>
</target>
<target name="compile" depends="prepare">
<echo message="start compile!" />
<javac srcdir="${src.home}" destdir="${build.class}" debug="${compile.debug}" deprecation="${compile.deprecation}" optimize="$compile.optimize}">
<classpath refid="compile.classpath" />
</javac>
<copy todir="${build.class}">
<fileset dir="${src.res}">
<include name="**" />
</fileset>
</copy>
<echo message="complete compile!" />
</target>
<target name="deploy" depends="compile">
<mkdir dir="${deploy.home}" />
<copy todir="${deploy.home}">
<fileset dir="${build.home}" />
</copy>
<echo message="Successful Deployment" />
</target>
<target name="undeploy">
<delete dir="${deploy.home}" />
<delete dir="${cache.home}" />
<echo message="Successful UnDeployment" />
</target>
<!--
这也是一种打war包的方式
=============================================================================
<target name="jar" depends="compile">
<jar jarfile="${deploy.path}/${project.name}.war" basedir="${build.home}" />
<echo message="Successful packaging jar" />
</target>
=============================================================================
-->
<target name="deploywar" depends="compile" description="deploy the app as the war">
<war destfile="${deploy.path}/${project.name}.war" webxml="${build.web-inf}/web.xml">
<fileset dir="${build.home}">
<include name="**/*.*" />
</fileset>
</war>
</target>
<!--
=============================================================================
打包成jar
=============================================================================
-->
<target name="jar" depends="compile" description="make .jar file">
<delete dir="${doc.home}" />
<mkdir dir="${doc.home}" />
<jar destfile="${doc.home}/${project.name}.jar" basedir="${build.class}">
<manifest>
<attribute name="Specification-Title" value="${project.name}-${doc.title}" />
<attribute name="Created-By" value="吴移风" />
<attribute name="Specification-Version" value="${app.version}" />
<attribute name="Specification-Vendor" value="${doc.vendor}" />
</manifest>
</jar>
</target>
<!--
=============================================================================
输出并打包api文档成rar
=============================================================================
-->
<target name="doc" depends="jar,compile" description="create api doc">
<echo message="Running API Doc ..." />
<tstamp>
<format property="current.year" pattern="yyyy" />
</tstamp>
<javadoc sourcepath="${src.home}" destdir="${doc.home}/${project.name}" author="true" version="true" use="true" doctitle="&lt;h1&gt;${project.name}-${doc.title}-${app.version}&lt;/h1&gt;" windowtitle="${project.name}-${doc.title}-${app.version}" bottom="Copyright &amp;copy; 1998-${current.year} - ${doc.vendor}">
<classpath refid="compile.classpath" />
</javadoc>
<!-- 打包API文件和目录 -->
<echo message="Compressing API Doc ..." />
<zip destfile="${doc.home}/${project.name}-api.rar">
<zipfileset dir="${doc.home}" prefix="${doc.name}" />
</zip>
<!-- 打包之后清除构建的API文件和目录以及classes目录 -->
<echo message="Deleting classes ..." />
<echo message="Deleting API Doc ..." />
</target>
<!--
=============================================================================
tomcat task
=============================================================================
-->
<taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
<classpath>
<path location="${appserver.home}/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
<classpath>
<path location="${appserver.home}/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
<classpath>
<path location="${appserver.home}/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
<classpath>
<path location="${appserver.home}/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
<classpath>
<path location="${appserver.home}/lib/catalina-ant.jar" />
</classpath>
</taskdef>
<target name="install" description="install the application in Tomcat">
<install url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="${project.name}" war="${project.name}" />
</target>
<target name="reload" description="reload the application in Tomcat">
<reload url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="${project.name}" />
</target>
<target name="list" description="list All the application in Tomcat">
<list url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" />
</target>
<target name="start" description="start the application in Tomcat">
<start url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${project.name}" />
</target>
<target name="stop" description="stop the application in Tomcat">
<stop url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/PiccSystem" />
</target>
<!--
=============================================================================
start tomcat
=============================================================================
-->
<target name="start-tomcat-E">
<exec executable="cmd" dir="${appserver.home}/bin">
<arg value="/c" />
<arg value="startup.bat" />
</exec>
</target>
<target name="stop-tomcat-E">
<exec executable="cmd " dir="${appserver.home}/bin" spawn="true">
<arg value="/c" />
<arg value="shutdown.bat" />
</exec>
</target>
<target name="start-tomcat-D">
<exec executable="cmd" dir="${casserver.home}/bin">
<arg value="/c" />
<arg value="startup.bat" />
</exec>
</target>
<target name="stop-tomcat-D">
<exec executable="cmd " dir="${casserver.home}/bin" spawn="true">
<arg value="/c" />
<arg value="shutdown.bat" />
</exec>
</target>
</project>



project.name=PiccSystem
#----------------------------------------------------------
appserver.home=E:/apache-tomcat-6.0.14
casserver.home=D:/apache-tomcat-6.0.14
deploy.path=E:/apache-tomcat-6.0.14/webapps
tomcat.manager.url=http://localhost:8080/manager
tomcat.manager.username=admin
tomcat.manager.password=manager
build.home=build
#------
app.version=1.0
build.web-inf=build/WEB-INF
build.class=build/WEB-INF/classes
build.lib=build/WEB-INF/lib
src.webroot=WebRoot
src.home=src/main/java
src.res=src/main/resources
src.lib=WebRoot/WEB-INF/lib
src.web-inf=WebRoot/WEB-INF
deploy.home=E:/apache-tomcat-6.0.14/webapps/PiccSystem
cache.home=E:/apache-tomcat-6.0.14/work/Catalina/localhost
doc.home=E:/doc
doc.title=API
doc.vendor=Stone Age Co. Ltd.
compile.debug=true
compile.deprecation=false
compile.optimize=true

说明:提供编译,发布到tomcat,打war包。启动tomcat,停止tomcat,我这里使用的是eclipse,所以编译路径是build,如果你不是请相应修改,project.name是发布到tomcat的名称,还有WebRoot/WebContent,就是这些目录,大家如果有不同,修改properties文件就好了。
页: [1]
查看完整版本: 通用ANT编译发布打包启动tomcat的模板