Install and use Java ant

Source: Internet
Author: User

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

 

 

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.