◎ Use of ant-buildfile

Source: Internet
Author: User
◎ Use of ant-buildfile

Ant
Http://www.blogjava.net/x-29/archive/2007/04/09/109426.html

Now let's take a look at how to compile ant's buildfile.

Buildfile
Is an XML document named build. xml by default. In the buildfile of ant, we can set the attribute [property] and task [task ].
Multiple [Tasks] can be set in buildfile. These tasks can be source code compilation, Doc documentation generation,ProgramTesting, etc. These tasks are usually organized as a target.
[Target].

Let's take a look at a simple build. xml.

<
Project
Name
= "Addressbook"
Default
= "Compile"
Basedir
= "."
>


<! --
================================ Property definitions ========================= ============
-->


<
Property
Name
= "Tomcat. Home"
Value
= "C:/Jakarta-Tomcat"
 
/>


<
Property
Name
= "App. Home"
Value
= "."
 
/>

<
Property
Name
= "Src. Home"
Value
= "$ {App. Home}/src"
/>


<
Property
Name
= "Lib. Home"
Value
= "$ {App. Home}/WEB-INF/lib"
/>


<
Property
Name
= "Classes. Home"
Value
= "$ {App. Home}/WEB-INF/classes"
/>



<! --
============================== "Compile" target ============================ ==================
-->


<
Target
Name
= "Compile"

>


<
Javac
Srcdir
= "$ {SRC. Home }"
Destdir
= "$ {Classes. Home }"
Debug
= "Yes"
 
>


<
Classpath
RefID
= "Compile. classpath"
/>


</
Javac
>


</
Target
>


</
Project
>


In build. XML, the project acts as the root element (each buildfile has a project), and then defines two attributes and a target.

For the attributes of the project and target elements, see the following table.

Tag Attribute Description Required
Project Name Project name No
Default If no target is specified, the default target Yes
Basedir As the base path for calculating other paths. This attribute can be overwritten by the basedir property. This attribute is ignored when it is overwritten. If neither the attribute nor the basedir property is set, use the parent directory of the buildfile file. No
Target Name Target name Yes
Depends Target names separated by commas (,). If you set some attributes, this target will depend on the target set by depends. No
If Attribute name to be set for executing target No
Unless To execute target, clear the set attribute name No
Description Target description No


In use

D: \> ant

During execution, the system first enters the "complie" target (the ant above does not specify the target, so the default value of the project is used) and compiles the source code (javac task)

Tip: You can specify the target to be executed after ant. By default, the default target is used (that is, the target set by the default attribute of the project element ).
 

Connect
To run a program, you must first compile its source code, generate an executable file, and then run the executable file. It can be seen that this is composed of two tasks, and the dependency compilation for running Executable File tasks
Source code task. Ant buildfile can define multiple targets, and the execution of one target can depend on another target.
The depends attribute of the target element. You can set multiple targets (separated by commas), for example:

<
Target
Name
= "Run"
Depends
= "Mkdir, complie"
>


<! --

Run the program

-->


</
Target
>

"Run" depends on "mkdir" and "complie", that is, before running the program, you must first create a directory of relevant documents and compile the source code to generate executable files.
The dependency set in the depends attribute is executed in the left-to-right order and the command is executed.Ant run
The "mkdir" target will be executed first, and then "complie" will be executed before the "run" target will be executed.

<Property> element, mainly used to set some common attributes. Each attribute has a name, which will be explained later.

Let's talk about ant's buildfile. Next we will talk about ant's common task [task] labels.

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.