Manually deploy your own Java project with Apache Ant build

Source: Internet
Author: User
Tags echo message

Although Eclipse has inherited the ant plug-in from 3.0, it is not very useful to have a project that can be built automatically, but manually use the following

Ant to build its own Java project is also a meaningful thing, although now no one is using Javac Java command Line way to do the program ....

Ant is a tool under the Apache Fund project, and the official Apache explanation is a Java library and command-line tool that helps us build our software.

Apache Ant is a Java library and command-line tool, the Help building software. From apache.org ...

Currently, Apache Ant 1.9.4 is the most available version, see Therelease notes.

Click to download ant1.9.4
Apache-ant-1.9.4-bin.zip extract three additional environment variables onto the computer's disk

Set the ANT environment variable in window:

Ant_home DISK:/apache-ant-1.9.4

Path disk:/Apache-ant-1.9.4/bin

Classpath DISK:/apache-ant-1.9.4/lib

After the setup is complete, we'll test it. Open Windows+r input cmd
Entering the console input ant-version will output the version we found to be the output is 1.9.4

The second installment Jdk1.xxx casually installs a kind of university Java curriculum feeling,

After the installation is complete set up Java corresponding path and classpath then next we can build our own program through Ant.

The third is the generation of Helloworld.jar through Ant,

Create the project catalog D:\ant_test, and internally create the file Src and Lib class folders

Open command line settings set classpath=%classpath%;D: \ant_test\class set ClassLoader load path

Set path=%path%;D: \ant_test\class

Start writing the Ant.java code in the SRC directory as follows

public class ant{public   static void main (String []args)   {      System.out.println ("hello,world!");}   }
this time you didn't want to Javac and then Java ran ... Of course you can do this. But we can do it faster by writing ant configuration ...

The new build.xml content is as follows

<?xml version= "1.0"? ><project name= "Build"  basedir= "." >       <target name= "Buildpro" >               <javac srcdir= "src" destdir= "class"/>       </target>   <target name= "jarcmd" ><jar destfile= " Ant.jar "basedir=" Class >           <manifest>              <attribute name= "MainClass" value= "Ant"/> </           manifest>       </jar>      </target>  <target name= "Createjar" depends= "Buildpro,jarcmd" >      <echo message= "Generate Ant.jar"/>        <move file= "./ant.jar" tofile= "./lib/ant.jar"/>  </ Target></project>











Manually deploy your own Java project with Apache Ant build

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.