Use of the Automatic Build tool Ant (4)

Source: Internet
Author: User

For example, the directory contains the following build. xml file, which calls the ant. xml build file, as shown below:
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
 
<Project name = "FirstAnt" basedir = "." default = "run">
 
<Target name = "run">
 
<Ant antfile = "ant. xml"/>
 
</Target>
 
</Project>
The ant. xml file is as follows:
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
 
<Project default = "first">
 
<Description> description </description>
 
<Property name = "hello" value = "welcome"/>
 
<Target name = "first">
 
<Mkdir dir = "folder 1"/>
 
<Mkdir dir = "folder 2"/>
 
<Mkdir dir = "folder 3"/>
 
</Target>
 
</Project>

You can also call a target in another Build File during execution.
Antcall: This task indicates calling another target in the current build file ).
The attributes of the antcall task are as follows:

For example, if the directory contains the following build. xml file, the antcall task in the antcall target will be executed first, and the first target will be executed as follows:
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
 
<Project name = "FirstAnt" basedir = "." default = "antcall">
 
<Target name = "antcall">
 
<Antcall target = "first"/>
 
</Target>
 
<Target name = "first">
 
<Mkdir dir = "folder 1"/>
 
<Mkdir dir = "folder 2"/>
 
<Mkdir dir = "folder 3"/>
 
</Target>
 
</Project>
 

Copy: This task is used to copy files or directories.
The attributes of the copy task are as follows:

For example:
Copy a single file:
[Html]
<Copy file = "myfile.txt" tofile = "mycopy.txt"/>
Copy a single file to the specified directory:
[Html] view plaincopyprint?
<Copy file = "myfile.txt" todir = "../some/other/dir"/>
Copy a directory to another directory:
[Html]
<Copy todir = "../new/dir">
<Fileset dir = "src_dir"/>
</Copy>
Copy a batch of files to another directory, where fileset is the file set:
[Html]
<Copy todir = "../dest/dir">
<Fileset dir = "src_dir">
<Exclude name = "**/*. java"/>
</Fileset>
</Copy>
<Copy todir = "../dest/dir">
<Fileset dir = "src_dir" excludes = "**/*. java"/>
</Copy>
Copy a batch of files to the specified directory and add the. bak suffix after the file name:
[Html]
<Copy todir = "../backup/dir">
<Fileset dir = "src_dir"/>
<Globmapper from = "*" to = "*. bak"/>
</Copy>
Delete: This task is used to delete files or directories.
The attributes of a delete task are as follows:

For example:
Delete an object:
[Html]
<Delete file = "/lib/ant. jar"/>
Delete a specified directory and Its subdirectories:
[Html]
<Delete dir = "lib"/>
Delete a specified group of files:
[Html]
<Delete>
<Fileset dir = "." includes = "**/*. bak"/>
</Delete>
Delete a specified directory and Its subdirectories:
[Html]
<Delete multiple deemptydirs = "true">
<Fileset dir = "build"/>
</Delete>
Delete the subdirectory of a specified directory:
[Html]
<Delete multiple deemptydirs = "true">
<Fileset dir = "build" includes = "**/*"/>
</Delete>
Javac: This task is used to compile one or more Java source files. It usually requires two common attributes: srcdir and destdir, which are used to specify the location of the Java source file and the storage location of the compiled class file. The javac task does not have many attributes.
For example, the directory contains the following build. xml file:
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Project name = "FirstAnt" basedir = "." default = "compile">
<Target name = "compile">
<Mkdir dir = "Compiling folder"/>
<Javac srcdir = "." destdir = "compile folder" includeantruntime = "true"/>
</Target>
</Project>
The running result is as follows:

Java: This task is used to run a java class. Generally, the classname attribute is required to specify the class to be run.
 

For example, the directory contains the following build. xml file:
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Project name = "FirstAnt" basedir = "." default = "run">
<Target name = "run">
<Java classname = "HelloWorld"/>
</Target>
</Project>
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.