Java uses Ant script to generate war package whole process _java

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= "AWP" default= "Warfile" basedir= "." > <!--define attributes and make the name of the war package. --> <property name= "Warfilename" value= "Awp.war" ></property> <!--define the path and the jar package that is used to compile the Java file. --> <path id= "Project.lib" > <fileset dir= "${basedir}/lib" > <include name= "**/*.jar"/> ;/fileset> </path> <!--define tasks, empty tasks: Empty the original class file and create a new build path. --> <target name= "clean" > <delete dir= "${basedir}/src/main/webapp/web-inf/classes"/> <mkdir dir = "${basedir}/src/main/webapp/web-inf/classes"/> </target> <!--define tasks, compile the Java files in the Src folder, and put the compiled class file into the created Folder. --> <target name= "Build" depends= "clean" > <javac srcdir= "${basedir}/src/main/java" destdir= "${basedir}/s" Rc/main/webapp/web-inf/classes "Includeantruntime=" false "source=" 1.6 "target=" 1.6 "> <classpath refid=" Project.lib "> </claSspath> </javac> <!--copy Src/main/java non-Java file to/src/main/webapp/web-inf/classes--> <copy Todi R= "${basedir}/src/main/webapp/web-inf/classes" > <fileset dir= "${basedir}/src/main/java" > <include name = "**/**.*"/> <exclude name= "**/*.java"/> </fileset> </copy> </target> ;! --Define the default task and assemble the class file into a jar package. --> <target name= "warfile" depends= "Build" > <!--Package The jars under the Lib folder to Web-inf/lib--> <copy "$ {basedir}/src/main/webapp/web-inf/lib "> <fileset dir=" ${basedir}/lib "> </fileset> & Lt;/copy> <!--Create a new war package. --> <war destfile= "${basedir}/${warfilename}" webxml= "${basedir}/src/main/webapp/web-inf/web.xml" > <!- -Copies non-Jar and non-class files to the corresponding path of the war package. --> <fileset dir= "${basedir}/src/main/webapp" > <include name= "**/**.*"/> <exclude na Me= "**/*.jar"/> <exclude name= "**/*.class"/> </fileset> <!--Copy the Jar and class files to the corresponding path of the war package. --> <lib dir= "${basedir}/src/main/webapp/web-inf/lib"/> <classes "dir=" B-inf/classes "/> </war> </target> </project>

The above is the entire content of this article, I hope to help you learn.

Related Article

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.