ANT: 一个通用Build.xml模板的建立[转自蚂蚱Blog]
build.xml详解:
http://fykyx521.iteye.com/blog/543932
建立web应用的antbuild.xml模板
一、建立Web应用步骤
1、清空临时目录
2、建立目录结构
3、从vss或cvs中获得源文件
4、编译(编译java源文件、copy属性文件和xml等文件、编码转换)
5、建立WAR包
6、发布
二、建立web应用的build.xml模板
1.
<?xml version="1.0" encoding="UTF-8" ?> <project name="Hello world" default="doc" basedir="." > <!-- 要用到的其它文件定义的属性 --> <property file="build.properties"/> <property name="prj_dir" value=".."/> <!-- 定义一些常量 --> <property file="build.properties" /> <property name="conifg.dir" value="${prj_dir}/config" /> <property name="src.dir" value="${prj_dir}/src" /> <property name="report.dir" value="${prj_dir}/report" /> <property name="lib.dir" value="${prj_dir}/libs" /> <property name="dist.dir" value="${prj_dir}/dist" /> <property name="doc.dir" value="${prj_dir}/doc" /> <property name="test.dir" value="${prj_dir}/test" /> <property name="target.dir" value="${prj_dir}/target" /> <property name="classes.dir" value="${prj_dir}/WebRoot/WEB-INF/classes" /> <property name="target.classes.dir" value="${target.dir}/classes" /> <property name="target.testclasses.dir" value="${target.dir}/test-classes" /> <property name="webroot.dir" value="${prj_dir}/WebRoot" /> <property name="db.dir" value="${prj_dir}/db" /> <!-- 定义classpath --> <!-- 指明你所用到的jar包、class 文件存放的位置 --> <path id="master-classpath"> <fileset file="${lib.dir}/.*.jar" /> <pathelement path="${webroot.dir}/WEB-INF/classes" /> </path> <!-- 初始化任务 --> <target name="init" depends="clean"> </target> <!--清除所有输出目录--> <target name="clean" description="清空所有输出目录"> <echo message="清空所有输出目录"/> <delete dir="${target.classes.dir}" /> <delete dir="${target.testclasses.dir}" /> <delete dir="${target.dir}" /> <delete dir="${dist.dir}" /> <delete dir="${doc.dir}" /> </target> <!-- 编译 --> <target name="compile" depends="init" description="编译所有的java类"> <echo message="编译所有的java类"/> <mkdir dir="${target.classes.dir}" /> <javac srcdir="${src.dir}" destdir="${target.classes.dir}" target="1.6"> <classpath refid="master-classpath" /> </javac> </target> <!-- 测试 --> <target name="test" depends="compile" description="进行单元测试"> <mkdir dir="${report.dir}"/> <junit printsummary="on" haltonfailure="false" failureproperty="tests.failed" showoutput="true"> <classpath refid="master-classpath" /> <formatter type="plain"/> <batchtest todir="${report.dir}"> <fileset dir="${classes.dir}"> <include name="**WEB-INF/classes/" /> </fileset> <classes dir="${target.classes.dir}"></classes> <classes dir="${conifg.dir}"> <include name="*.properties" /> <include name="*.xml" /> <exclude name="applicationContext.xml" /> <exclude name="web.xml" /> </classes> <lib dir="${lib.dir}"> <include name="**" /> <exclude name="**/servlet-api.jar" /> <exclude name="**/j2ee*.jar" /> <exclude name="**/junit*.jar" /> </lib> </war> </target> <!-- 部署到tomcat webapps目录下--> <target name="deploy-war" depends="war" description="部署到tomcat webapps 目录下"> <echo message="部署BuyPower.war到tomcat的webapps下"/> <copy todir="${tomcat.deploy.dir}" overwrite="true" > <fileset dir="${dist.dir}"> <include name="buypower.war"/> </fileset> </copy> </target> <!-- 输出api文档 --> <target name="doc" depends="compile" description="创建api文档"> <mkdir dir="${doc.dir}" /> <javadoc destdir="${doc.dir}" author="true" version="true" use="true" windowtitle="Your Project API"> <packageset dir="${src.dir}" defaultexcludes="yes"> <include name="com/**" /> <!--所包含的包,这里需要根据实际进行改变 --> </packageset> <doctitle> <![CDATA[<h1>Your Project description</h1>]]></doctitle> <bottom> <![CDATA[<i>Your companny Name,Inc,All Rights Reserved.</i>]]></bottom> <tag name="todo" scope="all" description="To do:" /> </jav
2.
<?xml version="1.0"?> <!-- ======================================================================= build file ======================================================================= --> <project default="main" basedir="build"> <property name="file.war" value="myapp.war"/> <property name="dir.jdk" value="c:/jbuilderx/jdk1.4"/> <property name="dir.src" value="src"/> <property name="dir.classes" value="classes"/> <property name="dir.lib" value="lib"/> <property name="dir.web" value="web"/> <property name="vss.login" value="userId,password"/> <property name="vss.serverPath" value="i:\"/> <property name="vss.srcPath" value="/myproject/src"/> <property name="vss.libPath" value="/myproject/lib"/> <property name="vss.webPath" value="/myproject/webapp"/> <property name="server.ftp.userId" value="ftpuser"/> <property name="server.ftp.password" value="ftppassword"/> <property name="server.ftp.serverIp" value="192.168.0.1"/> <path id="project.class.path"> <pathelement location="${dir.classes}"/> <pathelement location="${dir.jdk}/jre/lib/rt.jar"/> <fileset dir="${dir.lib}"> <include name="**/*.jar"/> </fileset> </path> <target name="clean"> <delete dir="${dir.src}"/> <delete dir="${dir.classes}"/> <delete dir="${dir.lib}"/> </target> <target name="init" depends="clean"> <mkdir dir="${dir.src}"/> <mkdir dir="${dir.classes}"/> <mkdir dir="${dir.lib}"/> </target> <target name="getFromVcm" depends="init"> <vssget localPath="${dir.src}" login="${vss.login}" vsspath="${vss.srcPath}" recursive="true" serverPath="${vss.serverPath}" writable="true"/> <vssget localPath="${dir.lib}" login="${vss.login}" vsspath="${vss.libPath}" recursive="true" serverPath="${vss.serverPath}" writable="true"/> <vssget localPath="${dir.web}" login="${vss.login}" vsspath="${vss.webPath}" recursive="true" serverPath="${vss.serverPath}" writable="true"/> </target> <target name="compile" depends="getFromVcm"> <javac bootclasspathref="project.class.path" debug="true" deprecation="true" destdir="${dir.classes}" nowarn="false" target="1.2"> <src path="${dir.src}"/> </javac> <copy todir="${dir.classes}"> <fileset dir="${dir.src}"> <include name="**/*.properties"/> <include name="**/*.xml"/> <exclude name="ApplicationResources.properties"/> </fileset> </copy> <native2ascii encoding="GBK" src="${dir.src}" dest="${dir.classes}" includes="ApplicationResources.properties"/> </target> <target name="buildWar" depends="compile"> <war destfile="${file.war}" webxml="${dir.web}/WEB-INF/web.xml"> <lib dir="${dir.lib}"/> <classes dir="${dir.classes}"/> <fileset dir="${dir.web}"/> </war> </target> <target name="deploy" depends="buildWar"> <ftp server="${server.ftp.serverIp}" userid="${server.ftp.userId}" password="${server.ftp.password}"> <fileset dir="."> <include name="${file.war}"/> </fileset> </ftp> </target> <target name="main" description="" depends="deploy"/> </project>
相关推荐
chichichi0 2020-01-06
BitsPlayer 2020-05-29
roygbip 2020-02-16
BitsPlayer 2020-02-13
lrcoop 2020-02-03
BitsPlayer 2019-12-19
BitsPlayer 2019-12-14
xueliangEmail 2013-07-22
cailianren 2010-04-15
wugang0 2019-11-09
lustdevil 2011-08-28
evilvoid 2008-04-17
leonranri 2019-11-05
leeccr 2019-10-31
evilvoid 2010-02-02