Ant advanced use, ant command details, ant packaging, ant compilation, and then package and remove the JAR File

Source: Internet
Author: User
In daily project development, we often need to package for testing, especially in windows, while in Linux.
In this case, many programmers need to pack a package and pack a package later. These packages may be large. In fact, only the code is changed, while the jar package is basically unchanged.
Of course, many people may say automated testing. Well, what we need to do today is the first step of automated testing.
At this time, I can use ant to package and remove all jar files in the project. Then, load the JAR file to a specific location when the project's Tomcat is started.

In this way, the war package may only have a few MB and what is smaller. For details about how to dynamically load the JAR file, we will explain in the next chapter. In this chapter, we will first look at the build. xml configuration packaged by ant.

View Source Code:

<? XML version = "1.0" encoding = "UTF-8"?> <Project name = "nojar" default = "deleteclasses" basedir = ". "> <property name =" classes "value =" build/classes "/> <property name =" build "value =" build "/> <property name =" lib "Value = "webroot/WEB-INF/lib"/> <path id = "compile. jar "> <fileset dir =" $ {lib} "> <include name = "*. jar "/> </fileset> </path> <! -- Delete the build path --> <target name = "deletebuild"> <Delete dir = "build"/> <copy todir = "$ {classes}/COM/Herman/config"> <fileset dir = "$ {basedir}/src/COM/Herman/config"> <include name = "*"/> </fileset> </copy> </Target> <! -- Create the build/classes path, compile the class file to the build/classes path --> <target name = "compile" depends = "deletebuild"> <mkdir dir = "$ {classes}"/> <javac srcdir = "src" destdir = "$ {classes}" includeantruntime = "on" encoding = "UTF-8"> <classpath refID = "compile. jar "/> </javac> </Target> <! -- Create a war package --> <target name = "war" depends = "compile"> <war warfile = "$ {build}/nojar. war "webxml =" webroot/WEB-INF/web. XML "encoding =" UTF-8 "> <! -- Copy two folders under webroot except WEB-INF and META-INF --> <fileset dir = "webroot" primary des = "**/*. jsp"> </fileset> <! -- <Fileset dir = "webroot" primary des = "**/*. *" excludes = "META-INF, WEB-INF"/> --> <! -- Copy the jar package under the lib directory --> <! -- <Lib dir = "$ {lib}"/> --> <! -- Copy the class file under build/classes --> <classes dir = "$ {classes}"/> </war> </Target> <! -- Delete the bytecode file under classes in build/to reduce the total size of the war package --> <target name = "deleteclasses" depends = "war"> <! -- <Delete dir = "$ {classes}"> </delete> --> </Target> </Project>
Isn't it easy? Well, if you think this article is okay, please follow my blog!

Or join the QQ group: 135430763 to learn together!

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.