虽然现在maven很流行,我也看了下,屡屡浅尝辄止。还是比较喜欢ant,而且对于我当前的工作,ant也够用了,所以对maven的学习也就没了兴趣,仅剩下对新事物的热情。
一个较复杂的工程项目可能包含很多目录,包括源代码文件、资源文件、文档等等一系列的东东,而且在项目发布时,除了考虑自动化、方便性(比如从cvs取最新版本、编译、打包、关闭应用服务器、部署、重新启动服务器等等)以外,还要考虑一些用户级的问题(比如修改了页面js后,怎样保证用户端从服务器端下载最新的js而不是用其本地浏览器缓存的js),另外基于源代码安全性考虑,可能还要进行代码混淆编译等。
下边是我们在实际项目中使用的一个ant构建配置:代码
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- 功能:cvs更新、编译(同时混淆)、生成注册文件、给页面文件的css和js引用增加版本号、打包、部署、运行tomcat等
- 作者:huangyuanmu
- 日期:2008-07-02.
- -->
- <project basedir="." default="build" name="wxwtdz">
- <!-- property -->
- <property file="resource/ant.properties" />
- <property environment="env" />
- <property name="tomcat.path" value="${tomcat.path}" />
- <property name="server.mac" value="${server.mac}" />
- <property name="cvsroot" value="${cvs.root}" />
- <property name="cvs.password" value="${cvs.password}" />
- <property name="cvs.module.name" value="xxx项目" />
- <property name="websrc.dir" value="web" />
- <property name="src.common.dir" value="common" />
- <property name="src.shell.dir" value="shell" />
- <property name="src.sys.dir" value="sys" />
- <property name="src.hjgl.dir" value="hjgl" />
- <property name="src.pzgl.dir" value="pzgl" />
- <property name="src.sbzs.dir" value="sbzs" />
- <property name="src.zhcx.dir" value="zhcx" />
- <property name="src.zhdy.dir" value="zhdy" />
- <property name="src.zhjb.dir" value="zhjb" />
- <property name="src.scheduling.dir" value="scheduling" />
- <property name="src.resource.dir" value="resource" />
- <property name="src.rpc.dir" value="rpc" />
- <property name="customize.dir" value="customize" />
- <property name="customize.resource.dir" value="customize/resource" />
- <property name="build.dir" value="build" />
- <property name="dist.dir" value="dist" />
- <property name="deploy.dir" value="${tomcat.path}/webapps" />
- <property name="dest.jar" value="wtdz.jar" />
- <property name="dest.war" value="wtdz.war" />
- <property name="dest.dir" value="wtdz" />
- <property name="jdk.source" value="1.5" />
- <property name="jdk.target" value="1.5" />
- <property name="deploy.web.dir" value="wtdz" />
- <property name="training.dir" value="training" />
- <property name="training.resource.dir" value="training/resource" />
- <property name="training.war" value="wtdzcs.war" />
- <!-- patternset -->
- <patternset id="jar.pattern">
- <include name="**/*.jar" />
- </patternset>
- <patternset id="config.pattern">
- <include name="**/*.xml" />
- <include name="**/*.properties" />
- <include name="**/*.prop" />
- <include name="**/*.conf" />
- <include name="**/*.tld" />
- <include name="**/*.ftl" />
- <include name="**/*.vm" />
- </patternset>
- <patternset id="build.pattern">
- <include name="log" />
- <include name="**/*.jar" />
- <include name="**/*.class" />
- <include name="**/*.vm" />
- <include name="**/*.rep" />
- <include name="**/*.exe" />
- <include name="**/*.log" />
- <include name="**/*.bat" />
- <include name="**/*.xls" />
- <include name="**/*.xml" />
- <include name="**/*.properties" />
- <include name="**/*.prop" />
- <include name="**/*.conf" />
- <include name="**/*.tld" />
- <include name="**/*.ftl" />
- <include name="**/*.jsp" />
- <include name="**/*.htm" />
- <include name="**/*.html" />
- <include name="**/*.js" />
- <include name="**/*.css" />
- <include name="**/*.swf" />
- <include name="**/*.jpg" />
- <include name="**/*.gif" />
- <include name="**/*.png" />
- <include name="**/*.rar" />
- <include name="**/*.wmv" />
- <include name="**/*.mp3" />
- <include name="**/*.3gp" />
- <include name="**/*.doc" />
- <include name="**/*.htc" />
- <exclude name="WEB-INF/**/*" />
- <exclude name="**/web.xml" />
- </patternset>
- <patternset id="src.pattern">
- <include name="**/*.java" />
- <include name="**/*.vm" />
- <include name="**/*.rep" />
- <include name="**/*.exe" />
- <include name="**/*.xml" />
- <include name="**/*.xls" />
- <include name="**/*.properties" />
- <include name="**/*.prop" />
- <include name="**/*.conf" />
- <include name="**/*.tld" />
- <include name="**/*.ftl" />
- <include name="**/*.jsp" />
- <include name="**/*.htm" />
- <include name="**/*.html" />
- <include name="**/*.js" />
- <include name="**/*.css" />
- <include name="**/*.swf" />
- <include name="**/*.jpg" />
- <include name="**/*.gif" />
- <include name="**/*.png" />
- <exclude name="**/web.xml" />
- </patternset>
- <!-- path -->
- <path id="compile.classpath">
- <fileset dir="${tomcat.path}/lib">
- <patternset refid="jar.pattern" />
- </fileset>
- <fileset dir="${websrc.dir}/WEB-INF/lib">
- <patternset refid="jar.pattern" />
- </fileset>
- <fileset dir="${build.dir}/WEB-INF/classes">
- <patternset refid="build.pattern" />
- </fileset>
- </path>
- <!-- taskdef -->
- <!-- 给页面文件中的js和css引用增加版本号 -->
- <taskdef name="addVersion" classname="cn.xxx.wtdz.ant.task.AddJsAndCssVersionToVm" classpath="bin/ant-task.jar">
- </taskdef>
- <!-- 利用混淆器进行编译 -->
- <taskdef resource="jockytasks">
- </taskdef>
- <!-- 生成注册码文件 -->
- <taskdef name="genRegKey" classname="cn.xxx.wtdz.ant.task.GenRegKey" classpath="bin/ant-task.jar">
- </taskdef>
- <!-- target -->
- <!-- 删除构建发布文件夹 -->
- <target name="clean">
- <delete dir="${build.dir}" />
- <delete dir="${dist.dir}" />
- </target>
- <!-- 创建构建发布文件夹 -->
- <target name="init" depends="clean">
- <mkdir dir="${build.dir}" />
- <mkdir dir="${build.dir}/WEB-INF/classes" />
- <mkdir dir="${dist.dir}" />
- </target>
- <!-- cvs更新(check out) -->
- <target name="checkout">
- <cvspass cvsroot="${cvs.root}" password="${cvs.password}" passfile="ant-cvs.cvspass" />
- <cvs command="-q checkout -d wxwtdz -P" failonerror="true" dest=".." cvsroot="${cvs.root}" package="${cvs.module.name}" passfile="ant-cvs.cvspass" />
- </target>
- <!-- 从源文件夹中拷贝文件到构建文件夹中 -->
- <target name="copysrc" depends="init">
- <copy todir="${build.dir}/src" overwrite="true">
- <fileset dir="${src.common.dir}">
- </fileset>
- <fileset dir="${src.shell.dir}">
- </fileset>
- <fileset dir="${src.sys.dir}">
- </fileset>
- <fileset dir="${src.hjgl.dir}">
- </fileset>
- <fileset dir="${src.pzgl.dir}">
- </fileset>
- <fileset dir="${src.sbzs.dir}">
- </fileset>
- <fileset dir="${src.zhcx.dir}">
- </fileset>
- <fileset dir="${src.zhdy.dir}">
- </fileset>
- <fileset dir="${src.zhjb.dir}">
- </fileset>
- <fileset dir="${src.scheduling.dir}">
- </fileset>
- <fileset dir="${src.resource.dir}">
- <exclude name="log4j.xml"/>
- </fileset>
- <fileset dir="${src.rpc.dir}">
- </fileset>
- <fileset dir="${customize.resource.dir}">
- </fileset>
- </copy>
- <copy todir="${build.dir}">
- <fileset dir="${websrc.dir}">
- <exclude name="WEB-INF/classes/**/*" />
- </fileset>
- </copy>
- <copy todir="${build.dir}" overwrite="true">
- <fileset dir="${customize.dir}">
- <exclude name="resource/**" />
- </fileset>
- </copy>
- </target>
- <!-- 编译、拷贝文件 -->
- <target name="compile" depends="copysrc">
- <jocky jar="bin/jocky.jar" enable="true" level="private">
- </jocky>
- <javac srcdir="${build.dir}/src" destdir="${build.dir}/WEB-INF/classes" debug="true" source="1.5" target="1.5" >
- <classpath refid="compile.classpath" />
- </javac>
- <copy todir="${build.dir}/WEB-INF/classes" overwrite="true">
- <fileset dir="${build.dir}/src">
- <patternset refid="config.pattern" />
- </fileset>
- </copy>
- <delete dir="${build.dir}/src" />
- </target>
- <!-- 给页面文件中的css和js引用增加版本号 -->
- <target name="addPageVersion" depends="compile">
- <addVersion path="${build.dir}" />
- </target>
- <!-- 构建war包 -->
- <target name="build" depends="addPageVersion">
- <!--<target name="build" depends="compile">-->
- <delete file="${dist.dir}/${dest.war}" />
- <mkdir dir="${build.dir}/log" />
- <genRegKey path="${dist.dir}" key="${server.mac}"/>
- <war destfile="${dist.dir}/${dest.war}" webxml="${build.dir}/WEB-INF/web.xml">
- <webinf dir="${build.dir}/WEB-INF" />
- <fileset dir="${build.dir}">
- <patternset refid="build.pattern" />
- </fileset>
- <fileset file="${dist.dir}/key.properties">
- </fileset>
- </war>
- <delete file="${dist.dir}/key.properties" />
- </target>
- <!-- 构建试用版war包 -->
- <target name="buildDebug" depends="addPageVersion">
- <delete file="${dist.dir}/${dest.war}" />
- <mkdir dir="${build.dir}/log" />
- <war destfile="${dist.dir}/${dest.war}" webxml="${build.dir}/WEB-INF/web.xml">
- <webinf dir="${build.dir}/WEB-INF" />
- <fileset dir="${build.dir}">
- <patternset refid="build.pattern" />
- </fileset>
- </war>
- </target>
- <!-- 部署前先关闭tomcat,并压缩文件 -->
- <target name="zip" depends="addPageVersion">
- <echo message="now stopping tomcat service" />
- <exec dir="${tomcat.path}/bin" executable="cmd">
- <env key="CATALINA_HOME" path="${tomcat.path}" />
- <arg value="/c shutdown.bat" />
- </exec>
- <delete file="${deploy.dir}/${dest.war}" />
- <delete file="${deploy.dir}/${dest.dir}" />
- <genRegKey path="${build.dir}" key="${server.mac}"/>
- <zip destfile="${deploy.dir}/${dest.war}">
- <fileset dir="${build.dir}">
- <include name="**/*" />
- </fileset>
- </zip>
- </target>
- <!-- 解压文件,并启动tomcat -->
- <target name="deploy" depends="zip">
- <echo message="deploy web project to ${deploy.dir}..." />
- <unzip dest="${deploy.dir}/${deploy.web.dir}" overwrite="true" src="${deploy.dir}/${dest.war}">
- </unzip>
- <echo message="now starting tomcat service" />
- <exec dir="${tomcat.path}/bin" executable="java.exe">
- <env key="CATALINA_HOME" path="${tomcat.path}" />
- <arg line="-jar -Duser.dir=${tomcat.path} ${tomcat.path}/bin/bootstrap.jar start" />
- </exec>
- </target>
- <!-- 把项目所有class文件打包 -->
- <target name="archive" depends="compile">
- <delete file="${dist.dir}/${dest.jar}" />
- <jar destfile="${dist.dir}/${dest.jar}" basedir="${build.dir}/WEB-INF/classes" />
- </target>
- <!-- 导出远程调用接口程序(住房出租票证管理接口) -->
- <target name="buildrpc" depends="compile">
- <delete file="${dist.dir}/wtdz-rpc.jar">
- </delete>
- <mkdir dir="${build.dir}/rpc/src" />
- <mkdir dir="${build.dir}/rpc/classes" />
- <copy todir="${build.dir}/rpc/src">
- <fileset dir="${src.rpc.dir}">
- <exclude name="**/impl/*" />
- <exclude name="**/aop/*" />
- </fileset>
- </copy>
- <jocky enable="false">
- </jocky>
- <javac srcdir="${build.dir}/rpc/src" destdir="${build.dir}/rpc/classes" debug="true">
- <classpath refid="compile.classpath" />
- </javac>
- <jar destfile="${dist.dir}/wtdz-rpc.jar">
- <fileset dir="${build.dir}/rpc/classes" includes="**/*.class" />
- <zipfileset src="${websrc.dir}/WEB-INF/lib/hessian-3.1.3.jar">
- </zipfileset>
- </jar>
- <delete dir="${build.dir}/rpc/src">
- </delete>
- <delete dir="${build.dir}/rpc/classes">
- </delete>
- </target>
- <!-- 从源文件夹中拷贝文件到构建文件夹中 -->
- <target name="copysrcTraining" depends="copysrc">
- <copy todir="${build.dir}/src" overwrite="true">
- <!-- 培训版本:从training文件夹中拷贝文件到构建文件夹中 -->
- <fileset dir="${training.dir}">
- <include name="cn/**"/>
- </fileset>
- <fileset dir="${training.resource.dir}">
- </fileset>
- </copy>
- <copy todir="${build.dir}" overwrite="true">
- <fileset dir="${training.dir}">
- <include name="images/**"/>
- </fileset>
- </copy>
- </target>
- <!-- 编译、拷贝文件 -->
- <target name="compileTraining" depends="copysrcTraining">
- <jocky jar="bin/jocky.jar" enable="true" level="private">
- </jocky>
- <javac srcdir="${build.dir}/src" destdir="${build.dir}/WEB-INF/classes" debug="true" source="1.5" target="1.5" >
- <classpath refid="compile.classpath" />
- </javac>
- <copy todir="${build.dir}/WEB-INF/classes" overwrite="true">
- <fileset dir="${build.dir}/src">
- <patternset refid="config.pattern" />
- </fileset>
- </copy>
- <delete dir="${build.dir}/src" />
- </target>
- <!-- 给页面文件中的css和js引用增加版本号 -->
- <target name="addPageVersionTraining" depends="compileTraining">
- <addVersion path="${build.dir}" />
- </target>
- <!-- 构建war包 -->
- <target name="buildTraining" depends="addPageVersionTraining">
- <!--<target name="build" depends="compile">-->
- <delete file="${dist.dir}/${dest.war}" />
- <mkdir dir="${build.dir}/log" />
- <genRegKey path="${dist.dir}" key="${server.mac}"/>
- <war destfile="${dist.dir}/${dest.war}" webxml="${build.dir}/WEB-INF/web.xml">
- <webinf dir="${build.dir}/WEB-INF" />
- <fileset dir="${build.dir}">
- <patternset refid="build.pattern" />
- </fileset>
- <fileset file="${dist.dir}/key.properties">
- </fileset>
- </war>
- <delete file="${dist.dir}/key.properties" />
- </target>
- <target name="training" depends="buildTraining">
- <move file="${dist.dir}/${dest.war}" tofile="${dist.dir}/${training.war}"/>
- </target>
- </project>
时间: 2024-11-16 03:25:03