Go: An example of an Ant Build.xml instance under Java Eclipse

Source: Internet
Author: User

Ant is not really important in an eclipse integration environment, but some projects need to be used, and learning and understanding ant through Eclipse is a great way to write his demo to summarize the points and hopefully help everyone.

First, I test environment eclipse3.6 has automatically integrated the ant environment, so you do not have to download the configuration of the ant environment separately.

If you do not have an eclipse integration environment you can download the latest version of Ant http://www.apache.org/yourself
After extracting ANT, set Ant_home, add the bin directory under Ant_home directory (for example: Ant_home:d:\apache-ant-1.9.2,path:%ant_home%\bin) in PATH
Test method: Start-and-run-->cmd into command line-and type ant carriage return if you see
Buildfile:build.xml does not exist!
Build failed
Indicates that ant's settings have been completed.

Second, create a Java project, Anttestdemo create a test class Helloant.java

1 package com.zdz.ant.test; 2  3/** 4  * java ant Test 5  * @author Zheng 6  * 7 */  8 public class Helloant {9     \ public static void Main (string[] args) {         System.out.println ("Hello ant,by zdz!");     }13 14}

Create a Build.xml file under the project root directory, as follows:

Press CTRL + C to copy the code<textarea></textarea>Press CTRL + C to copy the code

Straight up for the sake of intuition.

Third, right click on Build.xml to run ant as shown:

Operation Result:

Buildfile:d:\workspace\anttestdemo\build.xmlinit:    [mkdir] Created dir:d:\workspace\anttestdemo\ Classescompile:    [Javac] compiling 1 source file to D:\workspace\AntTestDemo\classesbuild:      [jar] Building jar:d : \workspace\anttestdemo\helloant.jarrun:     [java] Hello ant,by zdz! BUILD successfultotal time:2 seconds

The build successful and expected results show that Ant ran successfully.

You may also be prompted with a warning includeantruntime

<target name= "Compile" depends= "init" >
<javac srcdir= "${src}" destdir= "${dest}"/>
</target>

Revision changed to

<target name= "Compile" depends= "init" >
<javac srcdir= "${src}" destdir= "${dest}" includeantruntime= "on"/>
</target>

That is , add Includeantruntime= "on" .

The result of this build is somewhat different, as it turns out to be the result below.

Buildfile:d:\workspace\anttestdemo\build.xmlinit:compile:build:run:     [java] Hello ant,by zdz! BUILD successfultotal time:312 milliseconds

Go: An example of an Ant Build.xml instance under Java Eclipse

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.