Detailed steps to generate a war package with an ant script __java development tools

Source: Internet
Author: User
preparation before using ant script

1, download an ant installation package. such as: Apache-ant-1.8.4-bin.zip. Extract to E disk.

2, configure environment variables. Added Ant_home:e:\apache-ant-1.8.4;path added: E:\apache-ant-1.8.4\bin.

3, check ant is configured to complete. Run->cmd input: ant-version. See if you want to print an ant version number. the essence of packing build the essence of a jar package

1, compile the Project src folder under the Java file, generate the corresponding class file.

2. Assemble all the class files into a jar package. to generate the essence of a war package

1, compile the Project src folder under the Java file, generate the corresponding class file.

2, the project webcontent in addition to the class file and jar package files, all copies to the war package of the corresponding directory.

3, will compile the generated class file, all copies to the war package Web-inf/classes folder.

4, the project Lib in the jar package, all copied to the war package under the Web-inf/lib. Finally compressed into a war package. an ant script code that generates the war package

<?xml version= "1.0" encoding= "UTF-8"?> <!--defines a project, and the default task is Warfile. --> <project name= "Visit" default= "Warfile" basedir= "." > <!--define attributes and make the name of the war package. --> <property name= "Warfilename" value= "Visitfiles.war" ></property> <!--define the path, the J used to compile the Java file AR package. --> <path id= "Project.lib" > <fileset dir= "${basedir}/webcontent/web-inf/lib" > <i Nclude name= "**/*.jar"/> </fileset> </path> <!--define tasks, clear tasks: Empty the original class file, create a new build path 。 --> <target name= "clean" > <delete dir= "${basedir}/build"/> <mkdir "dir=" ${basedir}/b Uild "/> </target> <!--define tasks, compile the Java files in the Src folder, and put the compiled class files under the Created folder. --> <target name= "compile" depends= "clean" > <javac srcdir= "${basedir}/src" destdir= "${basedir}/bui"
 LD "Includeantruntime=" false "> <classpath refid=" project.lib "> </classpath>       </javac> </target> <!--define the default task and set the class file into a jar package. --> <target name= "Warfile" depends= "compile" > <!--Delete the original war package. --> <delete dir= "${basedir}/${warfilename}"/> <!--to create a new war package.
            --> <war destfile= "${basedir}/${warfilename}" webxml= "${basedir}/webcontent/web-inf/web.xml" > <!--copy non-jar and non-class files to the corresponding path of the war package.
                --> <fileset dir= "${basedir}/webcontent" > <include name= "**/**.*"/>
            <exclude name= "**/*.jar"/> <exclude name= "**/*.class"/> </fileset> <!--copy the Jar and class files to the corresponding path of the war package. --> <lib dir= "${basedir}/webcontent/web-inf/lib"/> <classes "dir=" ${basedir}/build
        Gt </war> </target> </project>


 

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.