Ant installation, configuration

xiaoxiao2021-03-06  14

ANT install, configure Author: Cha Dong Email: chedongATbigfoot.com/chedongATchedong.com

Written in: 2003/05 Last Update: 03/03/2005 17:01:59 Feed Back >>

Copyright Notice: You can reprint anything, please sure to indicate the original source and author information and this statement by hyperlink. Http://www.chedong.com/tech/ant.html

Keywords: Ant Build.xml Javac

Summary: Ant is a Java-based automation scripting engine, the script format is XML. In addition to making Java compilation related tasks, Ant can also achieve a number of applications in a plugin.

Ant's basic concept: Ant installation: Unpack, set the path Ant: The best learning is just a simple and practical example start ... Ant's basic concept: Java's makefile When a code item is big, each It will become very complicated and repetitive subsequent, and repetition, so the Make script is completed in the C language to help these work. Application in Java is a platform-independent. Of course, these batch tasks are not completed with platform-related Make scripts. Ant itself is such a process scripting engine for automated calling programs to complete project compilation, packaging, test, etc. . In addition to Java-based platforms, the format of the script is based on XML, which is better to maintain than the Make script.

A series of tasks (Target) is set in each Ant script (default build.xml): For example, there may be the following tasks for a general project.

Task 1: Usage Print this script Help information (Default) Task 2: Clean <- Init Clear Initialization Environment Task 3: Javadoc <- Build <- Init Generate Javadoc Task 4: Jar <- Build <- INIT generates JAR task 5: All <- jar javadoc <- build <- in j 完成 完成: JAR Javadoc often contains a certain dependency between multiple tasks: such as putting the entire application packaging task ( This is based on the compilation task, and the compilation task depends on the entire environment initialization task (INIT).

Note: I see that the names in the Ant scripts in many projects are basically consistent, such as compilation. BUILD or Compile; package general call JAR or WAR; generate documents generally named javadoc or javadocs; Perform all task all. In each task, Ant will call some external applications according to the configuration and configure the corresponding parameters. Although Ant can call external applications very rich, it is actually 2,3: such as Javac Javadoc Jar et al. When the ANT is installed, add the path to the bin pointing to Ant in the system executable path, such as adding the following configuration on the GNU / Linux: Export Ant_Home = / Home / Antexport Java_Home = / USR / Java / J2SDK1.4.1Export Path = $ PATH: $ java_home / bin: $ ant_home / bin

After this is executed, if you do not specify the configuration file Ant to save the build.xml this configuration file, and the default task settings can point to the most common task, such as: build, or point to print help information. : USAGE tells users that there are those script options that can be used. Ant use

The best learning process is to understand the build.xml script in the Open source project, and then simplify into a simpler, Ant and Apache projects on Ant and Apache: Simple and easy to use, and adaptability is very Strong, because the establishment of these projects is often derived from the most direct needs of developers. The following is an example of a Weblucene application: Modify build.xml from JDOM:

< Property name = "name" value = "project_name" />

<=

Echo message = "" "/>

Default Task: Usage Prints help documents, tells those task options: available for Build, Jar, Javadoc, and Clean.

Initializing environment variable: INIT All tasks are done based on some basic environment variables, which is the foundation of subsequent other tasks. During the initialization process, 2 points can be easily set:

1 In addition to the use of the default Property sets the Java source path and output path, the settings in an external build.properties file are referenced, most of this Simple configuration users can understand the build.properties, after all, XML is more readable than the key value attribute file. With build.properties, you can easily liberate from compiled details.

2 ClassPath Settings: Used in: is equivalent to setting: classpath = / path / to / resin / lib / jsdk23.jar; /Path/to/project/lib/*.jar; file replication : Prepare-src creates a temporary SRC storage directory and output directory.

Compilation Task: Build compile ClassPath environment to find a reference to a PATH object

Package task: jar written by the Package Generation Project, "=============================================================================================================================00 ===================================== ->

Generate a Javadoc documentation task: javadoc

Clear temporary compilation file: clean < / delete> Todo: More task / extensions: (sample)

Test Tasks: JUnit Test Code Style Check Tasks: Checkstyle, Jalopy and other email alerts: You can send the output warning of these tasks to the developed user list, this task can be set automatically.

Reference:

Jakarta Ant: http: //ant.apache.org

Original source: http://www.chedong.com/tech/ant.html << Back

<< Back to home page

转载请注明原文地址:https://www.9cbs.com/read-49548.html

New Post(0)