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