Ant implements Java project to automatically build and package war

Source: Internet
Author: User
Tags create directory
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.