ANT configuration and installation !!! %!

Source: Internet
Author: User
ANT configuration and installation !!! %! -- Linux general technology-Linux programming and kernel information. The following is a detailed description. Copyright Disclaimer: You can reprint the document at will. During reprinting, you must mark the original source and author information of the article as hyperlinks and this statement.
Http://www.chedong.com/tech/ant.html

Keywords: ant build. xml javac


Summary:
Ant is a JAVA-based automated script engine in XML format. In addition to JAVA compilation tasks, ANT can also call many applications through plug-ins.


ANT's basic concepts:
ANT installation: unpack and set the path
ANT's use: the best learning is just a simple and practical example ......
ANT's basic concept: Java Makefile
When a code project is large, every re-compilation, packaging, testing, and so on will become very complex and repetitive. Therefore, the C language contains the make script to help you complete these tasks in batches. In Java, applications are platform-independent. Of course, these batch processing tasks will not be completed using the platform-related make scripts. ANT itself is such a process script engine, it is used to automatically call the program to compile, package, and test the project. In addition to JAVA, the script format is based on XML, which is better maintained than the make script.


Each ant script (build. xml by default) contains a series of tasks (targets). For example, a general project may require the following tasks.

Task 1: usage prints the help information of this script (default)
Task 2: clean <-- init clear the initialization environment
Task 3: javadoc <-- build <-- init to generate JAVADOC
Task 4: jar <-- build <-- init to generate JAR
Task 5: all <-- jar + javadoc <-- build <-- init: jar javadoc
The dependencies between multiple tasks are often included: for example, the entire application package task (jar) depends on the compilation task (build ), compilation tasks depend on the entire environment initialization task (init.

Note: The names of ant scripts in many projects are basically the same, for example, compiling is usually called build or compile; packaging is usually called jar or war; generally, the generated document is named javadoc or javadocs. all tasks are executed. In each task, ANT calls some external applications according to the configuration and runs them with corresponding parameters. Despite the wide variety of external applications that ANT can call, the most common ones are javac javadoc jar.
ANT Installation
After unpacking, you can add the path pointing to the ant bin in the system executable path. For example, you can add the following configuration to/etc/profile on GNU/Linux:
Export ANT_HOME =/home/ant
Export JAVA_HOME =/usr/java/j2sdk1.4.1
Export PATH = $ PATH: $ JAVA_HOME/bin: $ ANT_HOME/bin

After ant is executed in this way, if the configuration file ant is not specified, it will be searched for build by default. xml configuration file, and execute tasks according to the configuration file. The default task settings can point to the most common tasks, such as build, or print the help information: usage, tell the user which script options can be used.


Use of ANT

The best learning process is to understand the build in those open source projects. xml script, and then simplified into a simpler project based on your own needs. ANT and APACHE have many very Engineering Projects: simple and easy to use, and highly adaptable, because the establishment of these projects often comes from the daily direct needs of developers.
Here is an example of a WebLucene application: Modify build. xml from JDOM:




















































































Destdir = "$ {build. dest }"
Debug = "$ {debug }"
Optimize = "$ {optimize}">









Basedir = "$ {build. dest }"
Includes = "**"/>








Sourcepath = "$ {build. src }"
Destdir = "$ {build. javadocs }"
Author = "true"
Version = "true"
Use = "true"
Splitindex = "true"
Windowtitle = "$ {Name} API"
Doctitle = "$ {Name}">


















Default task: usage prints the help document, indicating the task options available: build, jar, javadoc, and clean.

Initialize environment variable: init
All tasks are initialized based on some basic environment variables, which is the basis of other tasks in the future. During environment initialization, you can set two points for convenience:

1 In addition to setting the JAVA Source Path and output path using the default property, it references the setting in an external build. properties file,

In this way, most simple configuration users only need to understand build. properties. After all, XML is less readable than the attribute file of key value. Using build. properties can also help other users to release the compilation details.

2 CLASSPATH settings: Use the following:






It is equivalent to setting: CLASSPATH =/path/to/resin/lib/jsdk23.jar;/path/to/project/lib/*. jar;

File Replication: prepare-src
Create a temporary SRC storage directory and an output directory.














Compile task: build
In the CLASSPATH environment during compilation, you can find a path object by referencing it.


Package task: jar
Package the application to generate the. jar file with the name of the project.





Basedir = "$ {build. dest }"
Includes = "**"/>


JAVADOC document generation task: javadoc






Sourcepath = "$ {build. src }"
Destdir = "$ {build. javadocs }"
Author = "true"
Version = "true"
Use = "true"
Splitindex = "true"
Windowtitle = "$ {Name} API"
Doctitle = "$ {Name}">




Clear the temporary compilation file: clean












TODO:
More tasks/extensions: (example)

Test task: JUnit Test
Code style check tasks: CheckStyle, Jalopy, etc.
Mail alarm task: you can send the output warning of these tasks to the specified user list. This task can be set to run automatically on a daily basis.

References:

Jakarta ANT:
Http://ant.apache.org

Reprinted! If there are similarities, they are ************!

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.