Ant seems to be a waste of time. Many open-source projects use ant anyway.
I also need to use it. The first step is getting started.
1. Download and install
Go to Apache official website to download a ant, http://ant.apache.org/
: Http://labs.mop.com/apache-mirror//ant/binaries/apache-ant-1.8.4-bin.zip
After decompression, set the environment variables (PATH) and ant_home (ant_home)
Path = % ant_home % \ bin;
Open CMD and enter ant-version:
The following message is displayed:
C: \ Documents ents and Settings \ Administrator> ant-version
Apache ant (TM) version 1.8.4 compiled on May 22 2012
2. Simple demo
Create a Java project demo and a class file. Antdemo. Java
Enter the followingCode:
1 PackageTest;2 3 Public ClassAntdemo {4Public Static VoidMain (string [] ARGs ){5System. Out. println ("this is ant demo! ");6 }7}
Create build. xml under the project root directory
1 <? XML version = "1.0" encoding = "UTF-8" ?> 2 < Project Name = "Demo" Default = "Compile" Basedir = "." > 3 < Property Name = "Classdir" Value = "$ {Basedir}/tempbuild/classes" /> 4 5 < Target Name = "Compile" > 6 <! -- Create class temp folder --> 7 < Mkdir Dir = "$ {Classdir }" /> 8 9 <! -- Java compile to Classes --> 10 < Javac Srcdir = "$ {Basedir}/src" Destdir = "$ {Classdir }" Includeantruntime = "True" > 11 12 </ Javac > 13 14 <! -- Run --> 15 < Java Classname = "Test. antdemo" > 16 < Classpath > 17 < Pathelement Path = "$ {Classdir }" /> 18 </ Classpath > 19 </ Java > 20 21 <! -- Package to jar --> 22 < Jar Destfile = "Demo. Jar" Basedir = "$ {Classdir }" > 23 < Manifest > 24 < Attribute Name = "Main-class" Value = "Antdemo" /> 25 </ Manifest > 26 </ Jar > 27 28 <! -- Delete temp dir --> 29 < Delete Dir = "$ {Basedir}/tempbuild" /> 30 31 </ Target > 32 33 </ Project >
Next we will run this task. Open CMD and enter the path of the build file,
C: \ Documents ents and Settings \ Administrator> ant-file E:/workspace/demo/build. xml
The result is displayed. The demo. jar file is displayed in the project root directory.
Next we will introduce the ant command.
Http://www.cnblogs.com/philander/articles/1782254.html