Basic syntax for generating jar packages for common Java projects (using ant packaging)

Source: Internet
Author: User

Save the following as Build.xml:

<?xml version= "1.0" encoding= "UTF-8"?>

<project name="Project name" basedir="." default="Jar">

     < Property &NBSP; name= " Src.dir " &NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Span style= "font-size:13px;color:navy;font-family: ' Courier New '" >value= " src " />

     < Property &NBSP; name= " Jar.dir " &NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Span style= "font-size:13px;color:navy;font-family: ' Courier New '" >value= " out " />

     < Property &NBSP; name= " Bin.dir " &NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Span style= "font-size:13px;color:navy;font-family: ' Courier New '" >value= " bin " />

     < Property &NBSP; name= " Lib.dir " &NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Span style= "font-size:13px;color:navy;font-family: ' Courier New '" >value= " Lib " />

<path id="classpath">

         <fileset   dir= " ${lib.dir} " &NBSP; includes= "**/*.jar" />

</path>

     <target &NBSP; name= " compile " >

<mkdir dir="${bin.dir}"/>

       <javac srcdir="${src.dir}" destdir="${bin.dir}" classpathref="Classpath"/>

</target>

     <target &NBSP; name= " clean "

        <delete &NBSP; file= " ${jar.dir}/${ Ant.project.name}.jar " />

        <delete &NBSP; dir= " ${bin.dir} " />

</target>

     <target &NBSP; name= " jar "   depends= " clean,compile " >

        <mkdir &NBSP; dir= " ${jar.dir} " />

        <jar &NBSP; destfile= " ${jar.dir}/${ Ant.project.name}.jar "   basedir= " ${bin.dir} " />

</target>

</project>

You only need to replace the project name, such as memcached, and the resulting jar is Memcached.jar.

The basic process of the jar target:

1) clean , clear the original bin and Span style= "font-family: ' Times New Roman '" >out directory, i.e. delete .class and .jar file

2) compile , using classpath Reference compile-time required jar , All files under src are compiled, generated by .class placed in bin in the directory.

3) Build the jar, Create a new out directory, and package all the files under the bin into the " project name . Jar"and place it in the Out directory.


Basic syntax for generating jar packages for common Java projects (using ant packaging)

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.