Author: powerise
What is ANT?
Ant is a BUILD tool based on Java and XML.
2 download, install ANT
Install ANT
Download the .zip file, unzipped to C: /rant1.3 (later reference to% Ant_HOME%)
2.1 Do you need to do some configuration before you run Ant.
· Add a bin directory to the PATH environment variable.
· Set the ANT_HOME environment variable, 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.
• Optionally, set the Java_Home environment variable (refer to the following advanced sections), 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.
2.2 Run Ant
Running Ant is very simple, when you correctly install Ant, just enter Ant.
n When you 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.
n You can specify whether one or more Targets can be performed. 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 produpe logging information without adornments
-logfile file use Given File for log output
-logger classname the class thing 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 touth the root of the filesystem and use the first one found
-Dproperty = Value Set Property to Value
example
Ant
Use the build.xml in the current directory to run Ant, perform 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
Use the Test.xml under the current directory to run Ant, perform a target called DIST. ANT -BUILDFILE TEST.XML -DBUILD = Build / Classes Dist
Use the Test.xml in the current directory to run Ant, perform a target called Dist, and set the value of the build property of the build / class.
3 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 Task section below)
3.1 PROJECTS
Project has the following properties:
Attribute Description Required
Name project name. no
Default uses the default Target Yes used when you do not specify Target
BaseDIR 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. NO
The description of the project appears in the form of a top
A project can define one or more Targets. A Target is a series of what you want to do. When performing Ant, you can choose to execute that Target. When there is no Target, use the Target determined by the Project's Default property.
3.2 Targets
A Target can rely on other Targets. For example, you may have a Target for compiler, a Target to generate an executable. You must compile the pass before generating an executable, so the target that generates executable files depends on compiling Targets. Ant will deal with this dependency.
However, it should be noted that Ant's Depends attribute specifies the order of Target should be executed - if the dependent target cannot be run, this depends has no effect on target specified dependencies.
Ant will perform each target in order (from left to right) in the order of Target in the Depends property. However, it is necessary to remember that as long as a Target relies on a Target, the latter will be executed first.
Assume that we have to perform Target D. From its dependency properties, you may think that C, then B, and final A is executed. Wrong, C depends on B, B depends on A, so before the A, then B, then C, and final D is executed.
A Target can only be executed once, and there are multiple Targets depending on it (see the above example).
If (or if not) certain attributes are set, a Target is executed. In this way, the process of Build is allowed to better control the process of the system according to the status of the system (Java Version, OS, command line attribute, etc.). 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:
Target will always be executed if there is no IF or UNSS attribute.
Optional Description attributes can be used to provide a line description for Target, which can be output by the -projecthelp command line option.
Well your TSTamp Task is a good practice in a so-called initial Target, and other Targets rely on this initial Target. To ensure that the initialization Target is the first Target that appears in other Target rerequisites. Most of the initial Target in this manual is "init".
Target has the following properties:
Attribute Description Required
Name Target's name YES
Depends is a list of names of the Target separated by a comma, that is, the dependent table. NO
IF performs the name of the attribute name you need to be set. NO
Unless executes the TARGET to clear the set properties name. NO
Description Brief Description About Target features. NO
3.3 Tasks
A Task is an executable code.
A Task can have multiple properties (if you like, you can call it as a variable). Attributes may only contain references to Property. These references will be parsed before TASK execution.
Below is a general constructor of Task:
Here Name is the name of Task, attributen is the property name, VALUEN is attribute value.
There is a built-in Task, as well as some optional Task, but you can also write your own task.
All Task has a Task name property. ANT uses attribute values to generate log information.
You can assign a ID attribute to Task:
Here TaskName is the name of Task, and Taskid is the unique identifier of this Task. With this identifier, you can reference the corresponding Task in the script. For example, you can do this in the script:
Task1.setfoo ("BAR");
script>
Set the Foo property of a Task instance. In another Task (written with Java), you can use the following statement to access the appropriate instance.
Project.getReference ("task1").
Note 1: If Task1 has not yet been run, it will not take effect (for example: not set attribute), if you are configuring it, everything you do will be overwritten.
Note 2: The future Ant version may not be compatible with the properties mentioned here, because it is likely that there is no Task instance at all, only PROXIES.
3.4 Properties
A Project can have a lot of Properties. You can set it in buildfile, or set outside ANT. A Property has a name and a value. Property can be used for the attribute value of Task. This is achieved by placing the property name between "$ {" and "}" and placed at the property value. For example, if there is a value of a Property BuildDir is "build", this property can be used for attribute values: $ {builddir} / classes. This value can be parsed to Build / Classes.
Built-in attribute
If you use
To get a list of system properties, you can refer to The JavaDoc of System.getProperties.
In addition to the Java system properties, Ant also defines some of their own built-in properties:
The absolute path of the BaseDir Project base catalog (like the Basedir property of
ANT.FILE BuildFile's absolute path.
Ant.Version Ant version.
Ant.project.name The name of the current executed Project; setting it by the Name property of
Ant.java.version Ant detected JVM version; current value has "1.1", "1.2", "1.3" and "1.4".
example
target>
target>
target>
target>
provject>
3.5 Path-Like Structure
You can use ":" and ";" as a separator, specify a reference similar to PATH and ClassPath. ANT converts the separator to the separator used in the current system.
Nesting elements can be used when you need to specify a value of similar paths. General form is
claspath>
The Location property specifies a file and directory relative to the Project base, and the Path property accepts a comma or a semicolon separated list. Path properties are generally used as a predefined path - in other cases, multiple location properties should be used.
For the sake of simplicity, the ClassPath tag supports its own path and location attributes. and so:
claspath>
Can be disconnected:
The path can also be specified by the
fileset>
claspath>
The above example constructs a path value including: $ {classpath}, followed by all JAR files in the lib directory, followed by the classes directory.
If you want to use the same path-like Structure in multiple task, you can define them with the
Path-Like Structure may include reference to another path-like structure (by nested
fileset>
path>
path>
The brief way to
path>
Can be written:
Command line variable
Some TASK accept parameters and pass it to another process. In order to include a space character in the variable, nested Arg elements can be used.
Attribute Description Required
Value a command line variable; can contain space characters. Can only use one
Line space separated list of command line variables.
File as the file name of the command line variable; will be replaced by the absolute name of the file.
A string of path-like as a single command line variable; or as a separator, Ant converts it into a separator of a particular platform.
example
Is a single command line variable containing spaces.
It is two space separated command line variables.
Is a command line variable, which is on the DOS system / dir; / dir2; / dir3; / dir2: / dir3 on the UNIX system.
References
The ID attribute of the buildfile element can be used to reference these elements. If you need a copy of the same XML code block over and over again, this property is useful - such as using the
The following example:
claspath>
rmic>
target>
claspath>
javac>
target>
provject>
It can be written as follows:
path>
rmic>
target>
javac>
target>
provject>
All Tasks using patternsets, FileSets, or Path-Like Structures nested elements are also accepted by this type.
This post is edited by Powerise at 3:18 pm in 2004-2-24.
/ **
* personal opinion
* for reference only
* /
Powerise [ordinary users] posts: 1,163 Active points: 1,165 Technical Points: 132 available currency: 715 Registration time: 2003-1-21 User Status: Normal
Re: Ant Raiders (on) Submitted: 2004-2-24 12:03:05
Reply Send Message Ant Raiders (continued) - Built-in Task in Ant 4.1 File (Directory) Class 4.1.1 MKDIRN Create a directory, if his parent directory does not exist, it will be created at the same time. n example:
BAK suffix
GSTIDE [Normal User] Post: 11 Active Points: 11 Technical Points: 0 Free Coin: 1 Registration Time: 2003-1-17 User Status: Normal
Re: Ant Raiders (on) Summary: 2004-2-24 12:37:04
Reply message good
Love
QHDTELE [Normal User] Post: 166 Active Points: 163 Technical Points: 0 Free Coin: 158 Registration Time: 2003-12-31 User Status: Normal
RE: ANT Raiders (on) Submitted: 2004-2-24 13:10:14
Reply to the news there can download to Ant ??
Snowmanjy [ordinary users] Posts: 19 Active points: 19 Technical points: 0 available currency: 19 Registration time: 2002-8-27 User status: normal
Re: Ant Raiders (on) Summary: 2004-2-24 13:13:05
Reply message http://ant.apache.org/
Powerise [ordinary users] posts: 1,163 Active points: 1,165 Technical Points: 132 available currency: 715 Registration time: 2003-1-21 User Status: Normal
Re: Ant Raiders Submitted: 2004-2-24 15:19:00
Reply message ANT Raiders - Java Related Tasks 4.2.1 Javacn Compile Java Original Code N example 1. Javac srcdir = "$ {src}" destdir = "$ {build}" classpath = "xyz.jar" debug = "On" /> Compile $ {src} directory and all of its subdirectory. Java file,. The Class file will be placed in the directory specified by $ {build}, the classpath indicates the class file or directory you need to use, and debug is set to ON to indicate output Debug information 2.
The class file will be placed in the directory specified by $ {build}, the classpath indicates the class file or directory you want to use, and the debug is set to ON to indicate the output debug information 3.
Powerise [ordinary users] posts: 1,163 Active points: 1,165 Technical Points: 132 available currency: 715 Registration time: 2003-1-21 User Status: Normal
Re: Ant Raiders Submitted: 2004-2-24 15:19:36
Reply to send a message Ant Raiders ----- Package related task 4.3 Packing related 4.3.1 JARN Pack a set of files N: 1.
Web-inf / web.xmlweb-inf / lib / jdbc2.jarweb-inf / class / com / myco / myapp / servlet.classmeta-inf / manifest.mfindex.htmlfront.jspimages / small / logo. GIF4.3.3 EARN for packaged enterprise application n example
Powerise [ordinary users] posts: 1,163 Active points: 1,165 Technical Points: 132 available currency: 715 Registration time: 2003-1-21 User Status: Normal
RE: ANT Raiders Submitted: 2004-2-24 15:20:15
Reply send message ANT Raiders - Implementation Time Stamp 4.4 Timestamp Use the current time and date in the generated environment, tag a generated task in some way to record when it is generated, this is often desirable . This may involve editing a file to insert a string to specify the date and time, or merge this information into the file name of the JAR or ZIP file. This needs is solved by simple but very useful TSTAMP tasks. This task is usually called at the beginning of a certain generation process, such as in an init target. This task does not require attributes, and only
Powerise [ordinary users] posts: 1,163 Active points: 1,165 Technical Points: 132 available currency: 715 Registration time: 2003-1-21 User Status: Normal
Re: Ant Raiders Submitted: 2004-2-24 15:21:03
Reply message ANT Raiders - Execute SQL Statements via JDBC 4.5 Execute SQL Statements N An example: 1.
Powerise [ordinary users] posts: 1,163 Active points: 1,165 Technical Points: 132 available currency: 715 Registration time: 2003-1-21 User Status: Normal
Re: Ant Raiders Submitted: 2004-2-24 15:21:49
Reply to send a message This is the content inside a document that is made by others, and there will be more content, so stay tuned.
/*** personal opinion for reference only*/
Oursii [ordinary users] posts: 265 Active points: 277 Technical Points: 0 available currency: 197 Registration time: 2003-9-19 User Status: Lock
Re: Ant Raiders Submitted: 2004-2-24 16:14:05
Reply message is expected!
CCBKEJC [ordinary users] Post: 7 Active points: 7 Technical points: 0 available currency: 2 Registration time: 2004-1-11 User status: normal
Re: Ant Raiders Submitted: 2004-2-24 16:58:02
Reply message is good, I am trying to use Ant, collect
Dujl [ordinary users] posts: 93 Active points: 93 Technical Points: 0 available currency: 13 Registration time: 2003-10-31 User status: normal
Re: Ant Raiders Submitted: 2004-2-24 22:03:07
Reply to send a message is so troublesome, is there an automatic generation tool? After all, I don't want to spend too much time in this area!
http://www.perl.cnhttp://www.chinabcb.com
Powerise [ordinary users] posts: 1,163 Active points: 1,165 Technical Points: 132 available currency: 715 Registration time: 2003-1-21 User Status: Normal
Re: Ant Raiders Submitted: 2004-2-25 9:04:17
Reply message Ant Raiders --- Send Mail 4.6 Sending Mail N Use SMTP Server Send Mail N:
Liuyi8903 [ordinary users] Posts: 29 Active points: 29 Technical points: 0 available currency: 29 Registration time: 2003-3-3 User status: normal
Re: Ant Raiders Submitted: 2004-2-25 9:35:58
Thank you for your reply, thank you :)