Ant implements Java project to automatically build and package war
Pack a war based on NetBeans
1. Directory structure
ProA
proB ...
src java source Edit Directory
... WebRoot Web File storage Place
... Web-inf ...
lib jar package (class library) storage directory ... build compilation generated class file storage directory ...
dist War and Javadoc repository directory
... build.xml ant script
The goal is to build prob, but Prob's compilation relies on the ProA build jar, only to be referenced in the Lib directory of prob after the ProA build succeeds
2.build.xml is as follows
<?xml version= "1.0" encoding= "UTF-8"?> <project name= "ProB" default= "war" basedir= "." > <property name= "src.dir" value= "src"/> <property name= "Lib.dir" value= "Web-inf/lib"/> <p Roperty name= "Web.dir" value= "web"/> <property "name=" Web-inf.dir "value=" ${web.dir}/web-inf/> Erty name= "Build.dir" value= "Build"/> <property "name=" "Dist.dir" value= "Dist/> <property" class Es "value=" build/classes "/> <property name=" Libjar.dir "value=" Lib "/> <property" name= Truck "" value= ". ./"/> <!--Configure the jar package path to be referenced--> <path id=" Project.classpath "> <fileset dir=" ${libjar.dir } "> <include name=" **/*.jar "/> </fileset> <pathelement location=" ${build.di R}/classes "/> </path> <!--copy ProA build successful jar package to lib directory--> <target name=" Copy "> <c Opy todir= "${libjar.dir}" file= "${truck}/proa/build/proa.jar "/> </target> <!--delete build path--> <target name=" clear "depends=" Copy "> & Lt;delete dir= "${build.dir}"/> </target> <!--Create directory structure--> <target name= "init" depends= "Clea" R "> <mkdir dir=" ${classes} "/> </target> <!--build build/classes path and compile class file to Build/cl
Asses path--> <target name= "compile" depends= "init" > <javac srcdir= "src" destdir= "${classes}" >
<compilerarg line= "-encoding UTF-8-verbose"/> <classpath refid= "Project.classpath"/> </javac> </target> <!--copy the jar package in the Lib directory to web/web-inf/lib--> <target name= "Copyjar" D
epends= "Compile" > <copy todir= "${web.dir}/${lib.dir}" > <fileset dir= "${libjar.dir}" > </fileset> </copy> </target> <!--playing war package--> <target name= "WA R "depends=" Copyjar ">
<war destfile= "${dist}/tdtb.war" webxml= "Web/web-inf/web.xml" > <!--Copy Web folder--> <fileset dir= "${web.dir}"/> <!--the jar package--> <lib "dir=}" under the copy Lib directory
/> <!--copy build/classes class file--> <classes dir= "${classes}"/> </war> </target> </project>
3. Build a successful war package structure
ProB
... Meta-inf
... Web-inf
... Class
... Lib
... Web.xml
... redirect.jsp
Reference to specific parameters
Http://tech.it168.com/jd/2007-11-09/200711091344781_all.shtml