Compile, run, and package JAVA projects with Ant and generate api documents

Source: Internet
Author: User

Let's take a look at the Getting Started tutorial to learn how to install and use ant and the meanings of each component in the build. xml file.

The following is the document "build. xml", which is rewritten and pasted with a ready-made document of others. The two have slightly different attribute definitions.


[Html]
<! -- Verify validity -->
<? Xml version = "1.0"?>
<Project name = "HelloAnt" default = "api_doc" basedir = ".">
<Target name = "clean">
<Delete dir = "$ {basedir}/build"/>
</Target>
<! -- Compile -->
<Target name = "compile" depends = "clean">
<! -- There are no pre-defined variables to use and you can reorganize them yourself -->
<Mkdir dir = "$ {basedir}/build/classes"/>
<Javac srcdir = "$ {basedir}/src" destdir = "$ {basedir}/build/classes"/>
</Target>
<! -- Run -->
<Target name = "run" depends = "compile">
<Java classname = "HelloAnt">
<Classpath>
<Pathelement path = "$ {basedir}/build/classes"/>
</Classpath>
</Java>
</Target>
<! -- Package -->
<Target name = "jar" depends = "run">
<Jar destfile = "HelloAnt. jar" basedir = "$ {basedir}/build/classes">
<Manifest>
<Attribute name = "Main-class" value = "HelloAnt"/>
</Manifest>
</Jar>
</Target>
<! -- Generate document -->
<Target name = "api_doc" depends = "jar">
<Delete dir = "$ {basedir}/doc"/>
<Mkdir dir = "$ {basedir}/doc"/>
<Javadoc destdir = "$ {basedir}/doc" sourcepath = "$ {basedir}/src" package = "exer. * "author =" shoren "windowtitle =" MyPro API ">
<Doctitle> MyPro Project </doctitle>
<Bottom> Document by Shoren 2013. </bottom>
</Javadoc>
</Target>
</Project>

<! -- Verify validity -->
<? Xml version = "1.0"?>
<Project name = "HelloAnt" default = "api_doc" basedir = ".">
<Target name = "clean">
<Delete dir = "$ {basedir}/build"/>
</Target>
<! -- Compile -->
<Target name = "compile" depends = "clean">
<! -- There are no pre-defined variables to use and you can reorganize them yourself -->
<Mkdir dir = "$ {basedir}/build/classes"/>
<Javac srcdir = "$ {basedir}/src" destdir = "$ {basedir}/build/classes"/>
</Target>
<! -- Run -->
<Target name = "run" depends = "compile">
<Java classname = "HelloAnt">
<Classpath>
<Pathelement path = "$ {basedir}/build/classes"/>
</Classpath>
</Java>
</Target>
<! -- Package -->
<Target name = "jar" depends = "run">
<Jar destfile = "HelloAnt. jar" basedir = "$ {basedir}/build/classes">
<Manifest>
<Attribute name = "Main-class" value = "HelloAnt"/>
</Manifest>
</Jar>
</Target>
<! -- Generate document -->
<Target name = "api_doc" depends = "jar">
<Delete dir = "$ {basedir}/doc"/>
<Mkdir dir = "$ {basedir}/doc"/>
<Javadoc destdir = "$ {basedir}/doc" sourcepath = "$ {basedir}/src" package = "exer. * "author =" shoren "windowtitle =" MyPro API ">
<Doctitle> MyPro Project </doctitle>
<Bottom> Document by Shoren 2013. </bottom>
</Javadoc>
</Target>
</Project>
[Html]
<? Xml version = "1.0"?>
<Project name = "generate doc">
<! -- First define the variables to be followed -->
<Property name = "src. dir" location = "src"> </property>
<Property name = "build. dir" location = "build"> </property>
<Property name = "build. classes. dir" location = "$ {build. dir}/classes"> </property>
<Property name = "doc. dir" location = "doc"> </property>
<Property name = "zip_name" value = "ant_doc.zip"> </property>
<Property name = "zip. dir" location = "zip"> </property>
<Property name = "project_name" value = "ant_doc"> </property>

<Target name = "clean">
<Delete dir = "$ {build. dir}"> </delete>
<Mkdir dir = "$ {build. dir}"/>
<Mkdir dir = "$ {build. classes. dir}"/>
<Mkdir dir = "$ {doc. dir}"/>
<Mkdir dir = "$ {zip. dir}"/>
</Target>

<! -- Compile the source file -->
<Target name = "compile" depends = "clean">
<Javac srcdir = "$ {src. dir}" destdir = "$ {build. classes. dir}" failonerror = "true"> </javac>
</Target>

<! -- Generate doc document (not dependent on compilation) -->
<Target name = "build-doc">
<Javadoc sourcepath = "$ {src. dir}" package = "com. zf. *" destdir = "$ {doc. dir }"
Private = "true"
Charset = "UTF-8" docencoding = "UTF-8" encoding = "UTF-8">
<Classpath path = "$ {build. classes. dir}"> </classpath>
</Javadoc>
</Target>

<! -- Package -->
<Target name = "zip" depends = "compile, build-doc">
<Zip destfile = "$ {zip. dir}/$ {zip_name}" duplicate = "preserve">
<! -- Prefix specifies to add files to a specified folder -->
<Zipfileset dir = "$ {src. dir}" includes = "**/*. *" prefix = "$ {project_name}/src">
</Zipfileset>
<Zipfileset dir = "$ {doc. dir}" includes = "**/*. *" prefix = "$ {project_name}/doc/api">
</Zipfileset>
</Zip>
</Target>
</Project>

<? Xml version = "1.0"?>
<Project name = "generate doc">
<! -- First define the variables to be followed -->
<Property name = "src. dir" location = "src"> </property>
<Property name = "build. dir" location = "build"> </property>
<Property name = "build. classes. dir" location = "$ {build. dir}/classes"> </property>
<Property name = "doc. dir" location = "doc"> </property>
<Property name = "zip_name" value = "ant_doc.zip"> </property>
<Property name = "zip. dir" location = "zip"> </property>
<Property name = "project_name" value = "ant_doc"> </property>

<Target name = "clean">
<Delete dir = "$ {build. dir}"> </delete>
<Mkdir dir = "$ {build. dir}"/>
<Mkdir dir = "$ {build. classes. dir}"/>
<Mkdir dir = "$ {doc. dir}"/>
<Mkdir dir = "$ {zip. dir}"/>
</Target>

<! -- Compile the source file -->
<Target name = "compile" depends = "clean">
<Javac srcdir = "$ {src. dir}" destdir = "$ {build. classes. dir}" failonerror = "true"> </javac>
</Target>

<! -- Generate doc document (not dependent on compilation) -->
<Target name = "build-doc">
<Javadoc sourcepath = "$ {src. dir}" package = "com. zf. *" destdir = "$ {doc. dir }"
Private = "true"
Charset = "UTF-8" docencoding = "UTF-8" encoding = "UTF-8">
<Classpath path = "$ {build. classes. dir}"> </classpath>
</Javadoc>
</Target>
 
<! -- Package -->
<Target name = "zip" depends = "compile, build-doc">
<Zip destfile = "$ {zip. dir}/$ {zip_name}" duplicate = "preserve">
<! -- Prefix specifies to add files to a specified folder -->
<Zipfileset dir = "$ {src. dir}" includes = "**/*. *" prefix = "$ {project_name}/src">
</Zipfileset>
<Zipfileset dir = "$ {doc. dir}" includes = "**/*. *" prefix = "$ {project_name}/doc/api">
</Zipfileset>
</Zip>
</Target>
</Project>

 

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.