Detailed steps to generate a war package with an ant script

Source: Internet
Author: User

Preparation before using Ant script

1. Download an ant installation package. such as: Apache-ant-1.8.4-bin.zip. Unzip to the E-drive.

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

3. Check if Ant is configured to complete. Run->cmd input: ant-version. Check to see if the version number of the ant is printed.

The essence of the packaged essence of generating jar packages

1. Compile the Java file under the Project Src folder to generate the corresponding class file.

2. Assemble all the class files into a jar package.

The essence of generating a war package

1. Compile the Java file under the Project Src folder to generate the corresponding class file.

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

3. Compile the generated class files and copy them all to the war Package Web-inf/classes folder.

4, the project Lib jar package, all copied to the war package Web-inf/lib. Finally compress into a war package.

An ant script code that generates a war package
  • 1<?xml version= "1.0" encoding= "UTF-8"?>2   3<!--define a project, the default task is Warfile. -4<project name= "AWP"default= "Warfile" basedir= "." >5       6<!--define the property, and make the name of the war package. -7<property name= "Warfilename" value= "Awp.war" ></property>8       9<!--define the path, the jar package to use when compiling the Java file. -Ten<path id= "Project.lib" > One<fileset dir= "${basedir}/lib" > A<include name= "**/*.jar"/> -</fileset> -</path> the        -<!--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> +        A<!--define the task, compile the Java file in the Src folder, and put the compiled class file under the folder you created. - at<target name= "Build" depends= "clean" > -<javac srcdir= "${basedir}/src/main/java" destdir= "${basedir}/src/main/webapp/web-inf/classes" Includeantruntime= "false" source= "1.6" target= "1.6" > -<classpath refid= "Project.lib" > -</classpath> -</javac> -          in<!--copying Src/main/java non-Java files to/src/main/webapp/web-inf/classes--> -          to<copy todir= "${basedir}/src/main/webapp/web-inf/classes" > +<fileset dir= "${basedir}/src/main/java" > -<include name= "**/**.*"/> the<exclude name= "**/*.java"/> *</fileset> $</copy>Panax Notoginseng</target> -        the<!--define default tasks to assemble the class file into a jar package. - +<target name= "Warfile" depends= "Build" > A<!--package The jar under the Lib folder to Web-inf/lib- the          +<copy todir= "${basedir}/src/main/webapp/web-inf/lib" > -<fileset dir= "${basedir}/lib" > $                              $</fileset> -</copy> -<!--Create a new war package. - the<war destfile= "${basedir}/${warfilename}" webxml= "${basedir}/src/main/webapp/web-inf/web.xml" > -<!--copy non-jar and non-class files to the corresponding path of the war package. -Wuyi<fileset dir= "${basedir}/src/main/webapp" > the<include name= "**/**.*"/> -<exclude name= "**/*.jar"/> Wu<exclude name= "**/*.class"/> -</fileset> About<!--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= "${basedir}/src/main/webapp/web-inf/classes"/> -</war> -</target> A        +</project>

Detailed steps to generate a war package with an ant script

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.