Ant build.xml (模板)
阿新 • • 發佈:2019-02-11
<
?
xml
version
=
"1.0"
?
>
< project name= "your_porject_name" default= "deploy-db" >
< !-- properies -->
< !-- 定義一些常量 -->
< property file= "build.properties" / >
< property name= "src.dir" value= "${basedir}/src" / >
< property name=
"report.dir"
value=
"${basedir}/report"
/
>
< property name= "lib.dir" value= "${basedir}/lib" / >
< property name= "dist.dir" value= "${basedir}/dist" / >
< property name= "doc.dir" value= "${basedir}/doc" / >
< property name= "test.dir" value= "${basedir}/test"
/
>
< property name= "target.dir" value= "${basedir}/target" / >
< property name= "classes.dir" value= "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= "${basedir}/WebRoot" / >
< property name= "db.dir" value= "${basedir}/db" / >
< !-- 定義classpath -->
< !-- 指明你所用到的jar包、class 檔案存放的位置 -->
< path id= "master-classpath" >
< fileset file= "WebRoot/WEB-INF/lib/*.jar" / >
< pathelement path= "${webroot.dir}/WEB-INF/classes" / >
< / path>
< !--清除所有輸出目錄-->
< 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= "init" depends= "clean" >
< / 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.5" >
< 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= "**/*Test.*" / >
< / fileset>
< / batchtest>
< / junit>
< fail if= "tests.failed" >
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * 存在一個或多個錯誤 ,請檢查錯誤 . . . . . . * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
< / fail>
< / target>
< !--打包成jar -->
< target name= "pack" depends= "compile" description= "打jar包" >
< echo message= "生成your_project.jar" / >
< mkdir dir= "${dist.dir}" / >
< jar destfile= "${dist.dir}/your_porject.jar" basedir= "${classes.dir}" >
< exclude name= "**/*Test.*" / >
< exclude name= "**/Test*.*" / >
< / jar>
< / target>
< !-- WEB應用打成war包 -->
< target name= "war" depends= "pack" description= "打war包" >
< echo message= "生成your_project.war" / >
< mkdir dir= "${dist.dir}" / >
< jar destfile= "${dist.dir}/your_project.war" basedir= "${webroot.dir}" >
< exclude name= "**/*Test.*" / >
< exclude name= "**/Test*.*" / >
< / jar>
< / target>
< !-- 部署到tomcat webapps目錄下-->
< target name= "deploy-war" depends= "war" description= "部署到tomcat webapps 目錄下" >
< echo message= "部署your_project.war到tomcat的webapps下" / >
< copy todir= "${tomcat.dir}/webapps" overwrite= "true" >
< fileset dir= "${dist.dir}" >
< include name= "your_project.war" / >
< / fileset>
< / copy >
< / target>
< !-- 部署mysql資料庫檔案 -->
< target name= "deploy-db" depends= "deploy-war" description= "初始化mysql資料庫" >
< echo message= "部署資料庫檔案到mysql的data目錄下" / >
< copy todir= "${mysql.dir}/data" overwrite= "ture" >
< fileset dir= "${db.dir}" >
< include name= "**/*.*" / >
< / 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/pack/**" / > < !--所包含的包,這裡需要根據實際進行改變 -->
< / 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:" / >
< / javadoc>
< / target>
< / project>
< project name= "your_porject_name" default= "deploy-db" >
< !-- properies -->
< !-- 定義一些常量 -->
< property file= "build.properties" / >
< property name= "src.dir" value= "${basedir}/src" / >
< property name=
< property name= "lib.dir" value= "${basedir}/lib" / >
< property name= "dist.dir" value= "${basedir}/dist" / >
< property name= "doc.dir" value= "${basedir}/doc" / >
< property name= "test.dir" value= "${basedir}/test"
< property name= "target.dir" value= "${basedir}/target" / >
< property name= "classes.dir" value= "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= "${basedir}/WebRoot" / >
< property name= "db.dir" value= "${basedir}/db" / >
< !-- 定義classpath -->
< !-- 指明你所用到的jar包、class 檔案存放的位置 -->
< path id= "master-classpath" >
< fileset file= "WebRoot/WEB-INF/lib/*.jar" / >
< pathelement path= "${webroot.dir}/WEB-INF/classes" / >
< / path>
< !--清除所有輸出目錄-->
< 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= "init" depends= "clean" >
< / 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.5" >
< 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= "**/*Test.*" / >
< / fileset>
< / batchtest>
< / junit>
< fail if= "tests.failed" >
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * 存在一個或多個錯誤 ,請檢查錯誤 . . . . . . * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
< / fail>
< / target>
< !--打包成jar -->
< target name= "pack" depends= "compile" description= "打jar包" >
< echo message= "生成your_project.jar" / >
< mkdir dir= "${dist.dir}" / >
< jar destfile= "${dist.dir}/your_porject.jar" basedir= "${classes.dir}" >
< exclude name= "**/*Test.*" / >
< exclude name= "**/Test*.*" / >
< / jar>
< / target>
< !-- WEB應用打成war包 -->
< target name= "war" depends= "pack" description= "打war包" >
< echo message= "生成your_project.war" / >
< mkdir dir= "${dist.dir}" / >
< jar destfile= "${dist.dir}/your_project.war" basedir= "${webroot.dir}" >
< exclude name= "**/*Test.*" / >
< exclude name= "**/Test*.*" / >
< / jar>
< / target>
< !-- 部署到tomcat webapps目錄下-->
< target name= "deploy-war" depends= "war" description= "部署到tomcat webapps 目錄下" >
< echo message= "部署your_project.war到tomcat的webapps下" / >
< copy todir= "${tomcat.dir}/webapps" overwrite= "true" >
< fileset dir= "${dist.dir}" >
< include name= "your_project.war" / >
< / fileset>
< / copy >
< / target>
< !-- 部署mysql資料庫檔案 -->
< target name= "deploy-db" depends= "deploy-war" description= "初始化mysql資料庫" >
< echo message= "部署資料庫檔案到mysql的data目錄下" / >
< copy todir= "${mysql.dir}/data" overwrite= "ture" >
< fileset dir= "${db.dir}" >
< include name= "**/*.*" / >
< / 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/pack/**" / > < !--所包含的包,這裡需要根據實際進行改變 -->
< / 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:" / >
< / javadoc>
< / target>
< / project>