- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- ======================================================================
- ======================================================================
- -->
- <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">
- <!-- 项目lib下的所有jar -->
- <fileset dir="${src.lib}">
- <include name="**/*.jar" />
- </fileset>
- <!-- 项目tomcat lib下的所有jar -->
- <fileset dir="${tomcat.lib}">
- <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}" failοnerrοr="false" />
- <delete dir="${build.home}" failοnerrοr="false" />
- <delete file="${deploy.path}/${project.name}.war" failοnerrοr="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="<h1>${project.name}-${doc.title}-${app.version}</h1>" windowtitle="${project.name}-${doc.title}-${app.version}" bottom="Copyright &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=E:/apache-tomcat-6.0.14
- deploy.path=E:/apache-tomcat-6.0.14/webapps
- tomcat.manager.url=http://localhost:8080/manager
- tomcat.manager.username=ant
- tomcat.manager.password=secret
- 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
- src.res=src
- src.lib=WebRoot/WEB-INF/lib
- src.web-inf=WebRoot/WEB-INF
- tomcat.lib=E:/apache-tomcat-6.0.14/lib
- 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文件就好了。
<project basedir="." default="deploy" name="mac_web">
<target name="init">
<property name="Name" value="mac_web" />
<property name="name" value="mac_web" />
<property name="version" value="0.1" />
<property name="year" value="2011" />
<echo message="----------- ${Name} ${version} [${year}] ------------" />
<property name="debug" value="off" />
<property name="optimize" value="on" />
<property name="deprecation" value="on" />
<!-- java源文件路径 -->
<property name="src.dir" value="${basedir}/src" />
<!-- jar包路径 -->
<property name="lib.dir" value="${basedir}/mac_web/WEB-INF/lib" />
<!-- webapp路径 -->
<property name="webapp.dir" value="${basedir}/WebContent" />
<property name="packages" value="com.*.*.*" />
<!-- 准备源文件路径 -->
<property name="build.src" value="${basedir}/AntBuild/build" />
<!-- 编译源文件路径 -->
<property name="build.dest" value="${basedir}/AntBuild/bin" />
<!-- 准备webapp文件路径 -->
<property name="buildwar.dest" value="${basedir}/AntBuild/warsrc" />
<!-- 准备javadoc文件路径 -->
<property name="build.javadocs" value="${basedir}/AntBuild/doc" />
<!-- 打包jar文件路径 -->
<property name="jar.dest" value="${basedir}/AntBuild/jar" />
<!-- 打包war文件路径 -->
<property name="war.dest" value="${basedir}/AntBuild/war" />
<!-- classpath -->
<path id="classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
<!--<pathelement location="lib/"/>-->
</path>
<filter token="year" value="${year}" />
<filter token="version" value="${version}" />
<filter token="date" value="${TODAY}" />
<filter token="log" value="true" />
<filter token="verbose" value="true" />
</target>
<!-- =================================================================== -->
<!-- Help on usage -->
<!-- =================================================================== -->
<target name="usage" depends="init">
<echo message="${Name} Build file" />
<echo message="-------------------------------------------------------------" />
<echo message="" />
<echo message=" available targets are:" />
<echo message="" />
<echo message=" jar --> generates the ${name}.jar file" />
<echo message=" build --> compiles the source code" />
<echo message=" javadoc --> generates the API documentation" />
<echo message=" clean --> cleans up the directory" />
<echo message="" />
<echo message=" Please rename build.properties.default to build.properties" />
<echo message=" and edit build.properties to specify JSDK 2.3 classpath." />
<echo message="" />
<echo message=" See the comments inside the build.xml file for more details." />
<echo message="-------------------------------------------------------------" />
<echo message="" />
<echo message="" />
</target>
<!-- =================================================================== -->
<!-- 准备源文件-->
<!-- =================================================================== -->
<target name="prepare-src" depends="init">
<!-- create directories -->
<mkdir dir="${build.src}" />
<mkdir dir="${build.dest}" />
<mkdir dir="${jar.dest}" />
<mkdir dir="${war.dest}" />
<mkdir dir="${buildwar.dest}" />
<!-- copy src files -->
<copy todir="${build.src}">
<fileset dir="${src.dir}" />
</copy>
<copy todir="${buildwar.dest}">
<fileset dir="${webapp.dir}" />
</copy>
</target>
<!-- =================================================================== -->
<!-- 编译源文件-->
<!-- =================================================================== -->
<target name="build" depends="prepare-src">
<javac srcdir="${build.src}" destdir="${buildwar.dest}/WEB-INF/classes" debug="${debug}" optimize="${optimize}">
<classpath refid="classpath" />
</javac>
<copy todir="${buildwar.dest}/WEB-INF/classes">
<fileset dir="${build.src}">
<include name="**/*.xml" />
</fileset>
</copy>
</target>
<!-- =================================================================== -->
<!-- 打war包-->
<!-- =================================================================== -->
<target name="mac_web.war" depends="build">
<war warfile="${war.dest}/mac_web.war" webxml="${buildwar.dest}/WEB-INF/web.xml">
<lib dir="${buildwar.dest}/WEB-INF/lib" />
<classes dir="${buildwar.dest}/WEB-INF/classes" />
<fileset dir="${buildwar.dest}">
</fileset>
</war>
</target>
<!-- =================================================================== -->
<!-- 发布到本的resin和tomcat-->
<!-- =================================================================== -->
<target name="publish" depends="mac_web.war,clean">
<copy todir="${tomcat.home}/webapps">
<fileset dir="${war.dest}">
<include name="**/*.war" />
</fileset>
</copy>
</target>
<!--
<target name="SyncMain">
<java classname="com.ce.synchronization.main.SyncMain" failοnerrοr="true" fork="yes">
<classpath refid="classpath"/>
</java>
</target>
-->
<!-- =================================================================== -->
<!-- 产生javadoc api 文档-->
<!-- =================================================================== -->
<target name="javadoc" depends="build">
<mkdir dir="${build.javadocs}" />
<javadoc packagenames="${packages}" sourcepath="${build.src}" destdir="${build.javadocs}" author="true" version="true" use="true" splitindex="true" windowtitle="${Name} API" doctitle="${Name}">
<classpath refid="classpath" />
</javadoc>
</target>
<!-- =================================================================== -->
<!-- 清除临时文件-->
<!-- =================================================================== -->
<target name="clean" depends="init">
<delete dir="${build.src}" />
<delete dir="${build.dest}/org" />
<delete dir="${build.dest}/com" />
<delete dir="${buildwar.dest}" />
<delete>
<fileset dir="${build.dest}" includes="**/*.class" />
</delete>
</target>
<!-- Configure the directory into which the web application is built -->
<property name="build" value="${basedir}/webcontent/WEB-INF/classes" />
<property name="dist.dir" value="${basedir}/dist" />
<!-- Configure the context path for this application -->
<property name="path" value="/mac_web" />
<!-- Configure properties to access the Manager application -->
<property name="url" value="http://192.168.100.209:8090/manager" />
<property name="username" value="manager" />
<property name="password" value="admin" />
<!-- Configure the custom Ant tasks for the Manager application -->
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"/>
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask"/>
<target name="deploy" description="Install web application" depends="undeploy,mac_web.war,clean">
<deploy url="${url}" username="${username}" password="${password}" path="${path}" war="${war.dest}/mac_web.war" />
</target>
<target name="deployonly" description="Install web application" depends="init">
<deploy url="${url}" username="${username}" password="${password}" path="${path}" war="${war.dest}/mac_web.war" />
</target>
<target name="undeploy" description="Remove web application" depends="init">
<undeploy url="${url}" username="${username}" password="${password}" path="${path}" />
</target>
</project>
<project basedir="." default="deploy" name="mac_web">
<target name="init">
<property name="Name" value="mac_web" />
<property name="name" value="mac_web" />
<property name="version" value="0.1" />
<property name="year" value="2011" />
<echo message="----------- ${Name} ${version} [${year}] ------------" />
<property name="debug" value="off" />
<property name="optimize" value="on" />
<property name="deprecation" value="on" />
<!-- java源文件路径 -->
<property name="src.dir" value="${basedir}/src" />
<!-- jar包路径 -->
<property name="lib.dir" value="${basedir}/mac_web/WEB-INF/lib" />
<!-- webapp路径 -->
<property name="webapp.dir" value="${basedir}/WebContent" />
<property name="packages" value="com.*.*.*" />
<!-- 准备源文件路径 -->
<property name="build.src" value="${basedir}/AntBuild/build" />
<!-- 编译源文件路径 -->
<property name="build.dest" value="${basedir}/AntBuild/bin" />
<!-- 准备webapp文件路径 -->
<property name="buildwar.dest" value="${basedir}/AntBuild/warsrc" />
<!-- 准备javadoc文件路径 -->
<property name="build.javadocs" value="${basedir}/AntBuild/doc" />
<!-- 打包jar文件路径 -->
<property name="jar.dest" value="${basedir}/AntBuild/jar" />
<!-- 打包war文件路径 -->
<property name="war.dest" value="${basedir}/AntBuild/war" />
<!-- classpath -->
<path id="classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
<!--<pathelement location="lib/"/>-->
</path>
<filter token="year" value="${year}" />
<filter token="version" value="${version}" />
<filter token="date" value="${TODAY}" />
<filter token="log" value="true" />
<filter token="verbose" value="true" />
</target>
<!-- =================================================================== -->
<!-- Help on usage -->
<!-- =================================================================== -->
<target name="usage" depends="init">
<echo message="${Name} Build file" />
<echo message="-------------------------------------------------------------" />
<echo message="" />
<echo message=" available targets are:" />
<echo message="" />
<echo message=" jar --> generates the ${name}.jar file" />
<echo message=" build --> compiles the source code" />
<echo message=" javadoc --> generates the API documentation" />
<echo message=" clean --> cleans up the directory" />
<echo message="" />
<echo message=" Please rename build.properties.default to build.properties" />
<echo message=" and edit build.properties to specify JSDK 2.3 classpath." />
<echo message="" />
<echo message=" See the comments inside the build.xml file for more details." />
<echo message="-------------------------------------------------------------" />
<echo message="" />
<echo message="" />
</target>
<!-- =================================================================== -->
<!-- 准备源文件-->
<!-- =================================================================== -->
<target name="prepare-src" depends="init">
<!-- create directories -->
<mkdir dir="${build.src}" />
<mkdir dir="${build.dest}" />
<mkdir dir="${jar.dest}" />
<mkdir dir="${war.dest}" />
<mkdir dir="${buildwar.dest}" />
<!-- copy src files -->
<copy todir="${build.src}">
<fileset dir="${src.dir}" />
</copy>
<copy todir="${buildwar.dest}">
<fileset dir="${webapp.dir}" />
</copy>
</target>
<!-- =================================================================== -->
<!-- 编译源文件-->
<!-- =================================================================== -->
<target name="build" depends="prepare-src">
<javac srcdir="${build.src}" destdir="${buildwar.dest}/WEB-INF/classes" debug="${debug}" optimize="${optimize}">
<classpath refid="classpath" />
</javac>
<copy todir="${buildwar.dest}/WEB-INF/classes">
<fileset dir="${build.src}">
<include name="**/*.xml" />
</fileset>
</copy>
</target>
<!-- =================================================================== -->
<!-- 打war包-->
<!-- =================================================================== -->
<target name="mac_web.war" depends="build">
<war warfile="${war.dest}/mac_web.war" webxml="${buildwar.dest}/WEB-INF/web.xml">
<lib dir="${buildwar.dest}/WEB-INF/lib" />
<classes dir="${buildwar.dest}/WEB-INF/classes" />
<fileset dir="${buildwar.dest}">
</fileset>
</war>
</target>
<!-- =================================================================== -->
<!-- 发布到本的resin和tomcat-->
<!-- =================================================================== -->
<target name="publish" depends="mac_web.war,clean">
<copy todir="${tomcat.home}/webapps">
<fileset dir="${war.dest}">
<include name="**/*.war" />
</fileset>
</copy>
</target>
<!--
<target name="SyncMain">
<java classname="com.ce.synchronization.main.SyncMain" failοnerrοr="true" fork="yes">
<classpath refid="classpath"/>
</java>
</target>
-->
<!-- =================================================================== -->
<!-- 产生javadoc api 文档-->
<!-- =================================================================== -->
<target name="javadoc" depends="build">
<mkdir dir="${build.javadocs}" />
<javadoc packagenames="${packages}" sourcepath="${build.src}" destdir="${build.javadocs}" author="true" version="true" use="true" splitindex="true" windowtitle="${Name} API" doctitle="${Name}">
<classpath refid="classpath" />
</javadoc>
</target>
<!-- =================================================================== -->
<!-- 清除临时文件-->
<!-- =================================================================== -->
<target name="clean" depends="init">
<delete dir="${build.src}" />
<delete dir="${build.dest}/org" />
<delete dir="${build.dest}/com" />
<delete dir="${buildwar.dest}" />
<delete>
<fileset dir="${build.dest}" includes="**/*.class" />
</delete>
</target>
<!-- Configure the directory into which the web application is built -->
<property name="build" value="${basedir}/webcontent/WEB-INF/classes" />
<property name="dist.dir" value="${basedir}/dist" />
<!-- Configure the context path for this application -->
<property name="path" value="/mac_web" />
<!-- Configure properties to access the Manager application -->
<property name="url" value="http://192.168.100.209:8090/manager" />
<property name="username" value="manager" />
<property name="password" value="admin" />
<!-- Configure the custom Ant tasks for the Manager application -->
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"/>
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask"/>
<target name="deploy" description="Install web application" depends="undeploy,mac_web.war,clean">
<deploy url="${url}" username="${username}" password="${password}" path="${path}" war="${war.dest}/mac_web.war" />
</target>
<target name="deployonly" description="Install web application" depends="init">
<deploy url="${url}" username="${username}" password="${password}" path="${path}" war="${war.dest}/mac_web.war" />
</target>
<target name="undeploy" description="Remove web application" depends="init">
<undeploy url="${url}" username="${username}" password="${password}" path="${path}" />
</target>
</project>