What is ANT? 2. Install ANT3. Run ANT4. Write build.xml5. Built-in Task 6. Ear Task 7. War Task 8. JUnit Task (Internet) ----------- -------------------------------------------------- ------------------- 1. What is it? -------------------------------------------------- ---------------------------- Ant is a Java-based build tool. In theory, it is some similar (unix) Make, but there is no Make's defect. Since we already have make, gnumake, nmake, jam, and other build tools, why do you have a new build tool? Because Ant is developing software in a variety of (hardware) platforms, they cannot endure the limitations and inconveniences of these tools. Tools similar to MAKE is essentially a shell (language): they calculate dependencies, then execute commands (these commands are not very different from the command you are on command.). This means that you can easily extend the tool by using the OS unique or writing new (command) programs; however, this also means you limit yourself to a specific OS, or on a specific OS type, such as UNIX. Makefile is also very disgustable. Anyone who has used their people have encountered a variable Tab problem. Ant's original author often asked himself: "Is my order not executing just because there is a space before my tab ?!!". Tools similar to JAM handle such problems well, but (users) must remember and use a new format. Ant is different. Unlike the extended mode based on the shell command, ANT expands with Java classes. (Users) Don't have to write the shell command, the configuration file is based on XML, and all kinds of TASK can be performed by calling the Target tree. Each Task is run by an object that implements a specific TASK interface. (If you have no words to Ant, you may not understand this section, there is no relationship, you will introduce the Target, Task. You can even skip this section without too much time, then then Go back to browse the introduction here, then you will understand. Similarly, if you are not familiar with the tools such as Make, the following introduction will not use the concept in Make.) Must admit Some unique expressive capabilities will be lost when constructing the shell command. Such as `find. -Name foo -exec rm {}`, but gives you a cross-platform ability - you can work anywhere. If you really need to perform some shell commands, Ant has a
If you want you to compile Ant, you can get from http://jakarta.apache.org/builds/ant/release/v1.4.1/src. Note that the listed connections are the latest release of Ant. If you read this article, found that there is already an updated version, then use the new version. If you are a crazy technical pursuit, you can also download the latest version from Ant CVS Repository. System requirements want yourself build Ant. You need a JAXP-compatible XML parser (PARSER) in your ClassPath system variable. The binary form of Ant includes the latest version of the Apache Crimson XML parser. You can get more information about JAXP from http://java.sun.com/xml/. If you want to use other JAXP compatible parsers. You have to delete JAXP. JAR and CRIMSON.jar from the LIB directory of Ant. Then you can put your loved parser JAR file in the Ant's lib directory or put it in your ClassPath system variable. Ant installed Antbinary version includes three directories: BIN, DOCS, and LIB. Only the bin and lib directory are required to run Ant. To install Ant, select a directory and copy the release of the release to this directory. This directory is called Ant_Home. Do some configuration work before you run Ant. Add a bin directory to the PATH environment variable. Set the ANT_HOME environment variable to point to the directory where you install Ant. On some OS, Ant's script can guess Ant_Home (UNIX and WindOS NT / 2000) - but it is best not to rely on this feature. Alternatively, the Java_Home environment variable (refer to the following advanced section), which should point to the directory of the JDK installed. Note: Do not put the Ant.jar files of the Ant to the lib / ext directory of JDK / JRE. Ant is an application, and the lib / EXT directory is used for JDK extension (such as JCE, JSSE extension). And there will be security restrictions by extension. Optional Taskant supports some optional TASK. An optional Task generally requires an additional library to work. Optional Task is separated from the built-in Task of Ant, packaged separately. This optional package can be downloaded from the same place you download from Ant. The JAR file name called optional Task is called Jakarta-Ant-1.4.1-optional.jar. This JAR file should be placed in the lib directory of the Ant installation directory. The external library required for each optional Task can be referring to the dependent library section. These external libraries can be placed in the LIB directory of Ant, so Ant can be automatically loaded, or put it in an environment variable. Windows assumes that Ant is installed in a C: / Ant / directory. The following is a command to set the environment: set ant_home = c: / antset java_home = c: /jdk1.2.2set path =% path%;% ant_home% / binunix (bash) assumes that Ant is installed in / usr / local / ant directory . The following is a command to set the environment: export ant_home = / usr / local / antient / java_home = / usr / local / jdk-1.2.2export path = $ {pat}: $ {ant_home} / bin Advance To run Ant Many Variables. You at least reference requires the following content: Ant's classpath must contain ant.jar and the JAR file that you choose JAXP-compatible XML parser. When you need JDK's function (such as Javac or RMIC Task), for JDK 1.1, JDK's classs.zip file must be placed in ClassPath; for JDK 1.2 or JDK 1.3, you must join Tools.jar.
If the correct Java_Home environment variable is set, the script belongs in Ant, in the bin directory, automatically add the desired JDK class. When you perform a specific platform program (such as Exec Task or CVS Task), you must set the Ant.home property to point to the installation directory of Ant. Similarly, the scripts belled by the ANT use the ANT_HOME environment variable to automatically set this property. Building Ant If you want to install the Ant source code release or from the CVS in the CVS in the CVS. After installing the source code, enter the installation directory. Set the Java_Home environment variable points to the JDK installation directory. If you want to know how to do, please refer to install the ANT section. Make sure you have downloaded any auxiliary JAR file so that builds you are interested in Task. These JAR files can be placed in the classpath or placed in the lib / optional directory. See those JAR files in the dependent Task that can be seen from the Library section. Note that these JAR files are just used as build Ant. To run Ant, you have to set these JAR files as you do in the ANT section. Now you can build Ant of: build -Ddist.dir =
Jar Name Needed for available at an xsl transformer like xalan or xsl: p Style Task http://xml.apache.rg/xalan-j/index.html or http://www.clc-marketing.com/xslp/ jakarta -regexp-1.2.jar regexp type with mappers jakarta.apache.org/regexp/ jakarta-orom-2.0.1.jar regexp type with mappers and the perforce tasks jakarta.apache.org/oro/ junit.jar Junit Tasks WWW. Junit.org stylebook.jar style of xml.apache.org testlet.jar test task java.apache.org/framework antlr.jar ANTLR TASK www.antlr.org bsf.jar script task oss.software.ibm.com / developerworks / projects / bsf netrexx.jar netrexx task www2.hursley.ibm.com/netrexx rhino.jar javascript with script task www.mozilla.org jpython.jar python with script task www.jpython.org netcomponents.jar ftp and telnet Tasks www.savarese.org/oro/downloads 3. Run Ant ------------------------------------ -------------------------------------------- Run Ant is very simple, After you install Ant correctly, just enter Ant. When you do not specify any parameters, Ant will query the build.xml file in the current directory. If you find it, use this file as buildfile. If you use the -find option. Ant will look for BuildFile in the superiors until the root of the file system is reached. To allow Ant to use other buildfiles, you can use the parameter -Buildfile file, where the file specifies the buildfile you want to use. You can also set some properties to override the property value specified in the buildfile (see Property Task). You can use the -Dproperty = value option, where Property is the name of the attribute, and the value is the value of the attribute. This approach can also be used to specify the value of some environment variables. You can also use Property Task to access environment variables. Just pass -dmyvar =% myvar% (Windows) or -dmyvar = $ myvar (unix) to Ant - you can access these environment variables with $ {myvar} in your buildfile. There are two option -quite, telling Ant run only a small amount of necessary information. And -verbose tells Ant to output more information. You can specify one or more Targets. When Target is omitted, the ANT uses the target attribute specified by the Default property of the label
Command line option summary: Ant [options] [target [target2 [target3] ...] Options: -help print this message-projecthelp print project help information-version print the version information and exit-quiet be extra quiet-verbose be extra verbose-debug print debugging information-emacs produce logging information without adornments-logfile file use given file for log output-logger classname the class that is to perform logging-listener classname add an instance of class as a project listener-buildfile file use specified Buildfile-Find File Search for Buildfile Towards The root of the filesystem and use the first one found-dproperty = value set print - DPRUE Example Ant Use the build.xml in the current directory runs Ant, performs the default target. Ant -buildfile Test.xml Use the Test.xml in the current directory to run Ant, perform the default target. Ant -buildfile test.xml dist of Dist runs Ant using Test.xml in the current directory, performs a Target called DIST. ANT -BUILDFILE TEST.XML -DBUILD = BUILD / CLASSES DIST Use the Test.xml in the current directory running Ant, perform a Target called Dist and set the value of the build property of the build property. Files on UNIX, Ant's execution scripts will source before doing anything (read and calculate values) ~ / .antrc files; on Windows, Ant's batch file calls% home% / antc_pre.bat at the beginning, Call% home% / antc_post.bat at the end. You can use these files to configure or cancel some environment variables you need when you run Ant. Look at the example below. Environment Variable Wraps (Wrapper Scripts) Use the following environment variables (if any): JavaCMD Java executables absolute path. Use this value to specify a JVM different from java_home / bin / java (.exe). Ant_opts passed to the JVM command line variable - for example, you can define the maximum of the attribute or set the maximum of Java stacks Manually run Ant If you do your own installation (DIY) Ant, you can start Ant: java -dant.home with the following command = C: / Ant org.apache.tools.ant.main [Options] [target] This command is the same as the front Ant command. Options and Targets are also the same as when using an ANT command.
This example assumes your classpath contains: ant.jar jars / classes for Your XML Parser The JDK's Required Jar / Zip Files 4. Write build.xml ------------------- -------------------------------------------------- ----------- Ant's buildfile is written with XML. Each buildfile contains a Project. Each Task element in BuildFile can have an ID attribute that can be used to reference the specified task with this ID value. This value must be unique. (For details, please refer to the following Task section) ProjectsProject has the following properties: Attribute Description Required Name project name. No Default When the default Target Yes basedIr used when not specified Target is used to calculate the base path of all other paths. This property can be overwritten by BaseDir Property. This property is ignored when it is overwritten. If the attributes are not set, the parent directory of the buildfile file is used in BUILDIR PROPERTY. The description of the NO project appears in the form of a top
To make a target element, you should join the IF (or UNSS) property in the Target element, with the target of the determined attribute. For example: