ant-using ant to build a simple Java project (two)

Source: Internet
Author: User

The blog "ant-using ant to build a simple Java project (i)" demonstrates building a simple Java project using ant Tools, followed by this example to further learn Ant:

The above example requires running multiple ant commands to run the main function in the test class, can you simplify the need to run the command? The answer is yes, you can change the script in the Build.xml file to the following script:

<?

XML version= "1.0" encoding= "UTF-8"? ><project name= "Test" default= "Run-test" basedir= "." ><property name= "src" value= "src"/><property name= "Lib" value= "Build/lib"/><property name= "Dest" Value= "build/classes"/><property name= "Np_jar" value= "Build/lib/test.jar"/><target name= "Create-path" ><mkdir dir= "${dest}"/><mkdir dir= "${lib}"/></target><target name= "Create-class" depends= " Create-path "><javac srcdir=" ${src} "destdir=" ${dest} "/></target><target name=" Create-jar " depends= "Create-class" ><jar destfile= "${np_jar}" basedir= "${dest}" > <manifest> <attribute name= " Main-class "value=" Test "/> </manifest></jar></target><target name=" run-Test "depends=" Create-jar "><java classname=" Test "classpath=" ${np_jar} "/></target><target name=" clean ">< Delete file= "${np_jar}"/><delete dir= "${dest}"/><delete dir= "${lib}"/></target></project& Gt;

How does it do this by simply running the ant command and then running the "Ant Create-path", "Ant Create-class", "Ant Create-jar", and "Ant run-test" commands in order to complete the operation?

A, because the project label default property defines a value of run-test, when you run the ant command directly, Ant will first run the target named Run-test;

b, because the depends attribute in the target named Run-test points to the target named Create-jar, the target named Create-jar is run first;

C, because the depends property in the target named Create-jar, points to the target named Create-class. So the target of name Create-class will be run first;

D, because the depends attribute in target named Create-class points to target named Create-path, the target named Create-path is run first.

E, because the name is Create-path, the target does not have a depends attribute. So the ant command finally runs the target first.

Thus. Running the ant command alone now actually runs the "Ant Create-path", "Ant Create-class", "Ant Create-jar" and "Ant run-test" commands in turn.

The DOS form runs independently of the results of the ant command, for example:


Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

ant-using ant to build a simple Java project (two)

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.