Ant getting started
Author: Chen yuefeng
From: http://blog.csdn.net/mailbomb
Ant (another neat tool) is a mainstream build tool. Currently, almost all Java open-source projects use it to compile their own projects, the mainstream ide also provides good support for ant.
Ant is fully developed using the Java language and open source code. The latest version is 1.6.5, which can be easily used and scalable, the main task of using ant is to compile the corresponding build based on the needs of the build project. the XML file that uses the file control program to compile, run, package, and perform other operations.
Download U ant
Ant is an open-source and free software. You can download the latest version from the following address:
Http://ant.apache.org/
Installation and configuration of U ant
The ant installer is a compressed file. For example, the name of the ant 1.6.5installer in the latest version is --apache-ant-1.6.5-bin.zip.
1. Install ant
Ant installation is simple. Just decompress it. You can decompress the package to any directory as needed.
2. Ant Configuration
After installing ant, you need to configure two environment variables for ease of use:
A) path -- add the bin in the ant installation directory to the path.
B) ant_home -- Ant installation directory, for example, C:/ANT/Apache-ant-1.6.5.
In this way, you can use ant to build it under the command line.
U ant documentation
To learn how to use ant, read the ant documentation carefully. The ant user manual can be read from docs/manual/index.html under the ant installation directory. This is the best document to learn how to use ant and find ant labels.
Basic Format of U build. xml file
Ant writes the build. xml file, which is a standard XML file with the basic structure:
<? XML version = "1.0"?>
<Project>
<Target>
......
</Target>
</Project>
For more information about the roles and attributes of each tag, see the ant documentation.
U a simple example
Create a directory, such as D:/anttest, and create the following files and directories under this directory:
Ø build. xml
Ø src directory
L this directory contains main. Java
Ø classes directory
The content of these files is as follows:
<? XML version = "1.0"?>
<Project name = "test ant" default = "Nokia s40 1.0" basedir = ".">
<Description> build all version, include s40 1.0/s40 2.0/Moto, of this game </description>
<Target name = "Nokia s40 1.0" Description = "build s40 1.0 classes">
<Javac
Taskname = "javac Nokia s40 1.0"
Srcdir = "$ {basedir}/src"
Includes = ""
Destdir = "$ {basedir}/classes /"
/>
<Java
Taskname = "Java Nokia s40 1.0"
Classname = "test. Main"
Classpath = "$ {basedir}/classes"
/>
</Target>
</Project>
The source code of Main. Java is as follows:
Package test;
Public class main {
Public static void main (string [] ARGs ){
System. Out. println ("test ant ");
}
}
After the preceding directory structure is created, you can use ant to build the directory. You only need to switch the current directory to the D:/anttest directory in the command line and enter the ant command to execute it.
Of course, here we only implement the simplest ant function to help you quickly get familiar with ant usage. For more information and usage, please read the documentation provided by ant.