Learn more about the ant build toolTags: ant tools task Jarjavaclass2010-05-29 21:16 1346 People read comments (2) favorite reports
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Learn more about the ant build tool
When a project is very large, and every time it is recompiled, packaged, and tested very complex and repetitive, ant itself is a process scripting engine that automates the programming of the calling program to complete the project, package, and test. In addition to Java-based platform-agnostic, the script format is XML-based.
Ant Build File
When you start a new project, you should first write the ant build file. The build file defines the build process and is used by everyone in the team development. The ant build file is named Build.xml by default, or it can take other names. Just pass the name as a parameter to ant at run time. The build file can be placed in any location. The general practice is to keep the project concise and clear by placing it in the top-level directory of the project. The following is a typical project hierarchy.
(1) src deposit file.
(2) class holds the compiled file.
(3) Lib holds third-party jar packages.
(4) Dist Storage package, post code.
The ant build file is an XML file. Each build file defines a unique project (project Element). Many goals (target elements) can be defined under each project, and there can be dependencies between those goals. When such goals are implemented, the goals that they depend on are enforced.
Multiple tasks can be defined in each target, and the task sequence to be executed is also defined in the target. Ant must invoke the defined task when building the target. The task defines the command that ant actually executes. The tasks in ant can be 3 classes.
(1) Core tasks. The core task is Ant's own task.
(2) Optional tasks. Can be elected pragmatically from a third-party task, so an additional jar file is required.
(3) User-defined tasks. User-defined tasks real users develop their own tasks.
1.<project> Label
Each build file corresponds to one project. <project> tag is the root tag of the build file. It can have multiple intrinsic properties, as shown in the code, and the meanings of each of its properties are as follows.
(1) default indicates the run target, and this property is required.
(2) Basedir represents the base directory of the project.
(3) name indicates the project name.
(4) Description represents the description of the project.
Each build file corresponds to a project, but a large project often contains a large number of sub-projects, each of which can have its own build file.
2.<target> Label
You can have one or more target tags under a project tab. A target tag can depend on other target tags.
For example, there is a target for compiling a program, and another target for claiming an executable file. The file must be compiled before the executable can be generated, because the target of the executable file depends on the target of the compiler. All properties of target are as follows.
(1). Name indicates that this attribute is required.
(2). Depends indicates the target of dependence.
(3) If indicates that the property is set only when it is executed.
(4) unless indicates that the property does not execute when it is not set.
(5) Description represents the description of the project.
The ant's Depends property specifies the order in which target is executed. Ant executes each target sequentially, in the order in which the target appears in the Depends property. Before executing, you first need to execute the target that it depends on. The depends property of the target named run in the program is compile, and the depends property of the target named compile is prepare, so the order of these target executions is prepare->compile- >run.
A target can only be executed once, even if there are multiple target dependencies on it. If there is no if or unless attribute, target is always executed.
3.<mkdir> Label
The tag is used to create a directory that has a property, dir, to specify the name of the directory created, with the following code:
<mkdir dir= "${class.root}"/>
The above code creates a directory that has been specified by the previous property tag.
4<jar> Label
This tag is used to generate a jar file with the following properties.
(1) DestFile represents the jar file name.
(2) basedir indicates the file name to be archived.
(3) includes indicates that the file mode is not archived.
(4) exchudes indicates the excluded file mode.
5. <javac label >
This tag is used to compile one or a set of Java files with the following properties.
(1). Srcdir represents the directory of the source program.
(2). Destdir represents the output directory of the class file.
(3). Include indicates the mode of the compiled file.
(4). Excludes indicates the mode of the excluded files.
(5). Classpath represents the classpath used.
(6). Debug represents the debug information contained.
(7). Optimize indicates whether optimization is used.
(8). Verbose indicates that detailed output information is provided.
(9). Fileonerror means that it stops automatically when it encounters an error.
6. <java> tags
The tag is used to perform a compile-generated. class file with the following properties.
(1). classname represents the class name that will be executed.
(2). jar represents the jar file name that contains the class.
(3). The classpath used by the. Classpath.
(4). Fork indicates that the class is running in a new virtual machine.
(5). FailOnError indicates that it stops automatically when an error occurs.
(6). Output indicates the export file.
(7). Append indicates that the default file is appended or overwritten.
7.<delete> Label
This tag is used to delete a file or a set of files whose properties are as follows.
(1)/file represents the file to be deleted.
(2). Dir indicates the directory to be deleted.
(3). Includeemptydirs Indicates whether you want to delete the empty directory, and the default value is delete.
(4). FailOnError Indicates whether the default value is stopped automatically when an error is encountered.
(5). Verbose indicates whether the deleted file is listed, and the default value is not listed.
8.<copy> Label
This tag is used for a copy of a file or set of files with the following properties.
(1). file represents the source file.
(2). ToFile represents the target file.
(3). Todir represents the target directory.
(4). Overwrite indicates whether the destination file is overwritten, and the default value is no overwrite.
(5). Includeemptydirs indicates whether to copy an empty directory, and the default value is copy.
(6). FailOnError indicates that the default value is stop if the target is not found to stop automatically.
(7). Verbose Indicates whether detailed information is displayed and the default value does not display
Learn more about the ant build Tools command