Ant installation and configuration

Source: Internet
Author: User
J2EE related: ant installation and configuration
Posted on Tuesday, July 27 @ 11:33:03 CST by joezxh

Joe. Zhang shipping "Author: chedong Email: chedongatbigfoot.com/chedongatchedong.com
Last Update written on: 2003/05:

07/27/2004 11:13:47 feed back>

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.

    1. Ant's basic concepts:
    2. Ant installation: unpack and set the path
    3. Ant's use: the best learning is just a simple and practical example ......

Ant's basic concept: Java makefile
WhenCodeAfter the project is large, every re-compilation, packaging, testing, and so on will become very complex and repetitive, soC LanguageMake scripts are included 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 for automated calls.ProgramCompile, 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 Task 3: javadoc Task 4: jar Task 5: All

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.
After installing and uninstalling the ant package, 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
Generates the $ {name}. jar file "/>
Compiles the source code "/>
Generates the API documentation "/>
Cleans up the directory "/>
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

Source: http://www.chedong.com/tech/ant.html
"

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.