I: Introduction:
ant jakarta is a compilation tools, if you understand makefile under linux / Unix you can easily understand the use of the ant. ant is best for you to use UltraEdit (EditPlus) to write java program, and then you use ant to compile, and javadoc, generated a jar, war, realize copy files can be achieved through different tager go in build.xml, it is still very convenient a stuff is strongly recommended to use.
Two: download
you can download from the following address to the ant, the current version: 1.41
http://jakarta.apache.org/builds/jakarta-ant/release/v1.4.1/bin/
Three: Installation
A:) Windows
1: unzip the file you download, there will be a jakarta-ant directory (version number) to produce, he renamed Ant
2: Copy Ant directory to where you want.
3: Add the environment variable: ANT_HOME = ant installation directory, path and Canada $ ANT_HOME $ \ in; note that you must also have installed jdk, and add the JAVA_HOME environment variable, while early path added a $ JAVA_HOME $ \ in;
b:) Linux / Unix
1: unzip the file you downloaded, there will be a jakarta-ant directory (version number) to produce, he renamed Ant
2: Copy Ant directory to where you want.
3: Add the environment variable: ANT_HOME = ant installation directory, path and Canada $ ANT_HOME $ \ in; note that you must also have installed jdk, and add the JAVA_HOME environment variable, while early path added a $ JAVA_HOME $ \ in; to achieve modify environment variables you need to modify the .bash_profile file.
Following
the ANT_HOME = / usr / local / Ant
the JAVA_HOME = / usr / local / JDK
the PATH = $ the PATH: $ the HOME / bin: / usr / local / Ant / bin: / usr / local / JDK / bin
Export the PATH the ANT_HOME the JAVA_HOME
IV: write build.xml
build.xml quite Linux makefile under specific implementation are implemented in the build.xml.
I'll give an example to illustrate this point.
the build.xml
=============================================== =================
<Project name = "Bingo" default = "Build" basedir = "../ ..">
<-! basedir set the working directory - >
<Property name = "Version" value = "1.0" />
<!-- The base directory relative to which most targets are built -->
<property name="base" value="."/>
<!-- The directory where source files are stored. -->
<property name="java.source.dir" value="bingo/src"/>
<!--代码保存路径-->
<!-- Destination for compiled files -->
<property name="javac.dest" value="bingo/classes"/>
<!--class保存路径-->
<!-- Destination for generated jar files -->
<property name="jar.dest" value="bingo/jar"/>
<!--jar文件保存路径-->
<!-- Destination for documentation files generated or not -->
<name = Property "docs" value = "Bingo / docs" />
<-! javadoc file path ->
<!-- Destination for javadoc generated files -->
<property name="javadoc.dest" value="bingo/docs"/>
<!-- The stem where most log4j source code is located. -->
<property name="stem" value="com/bingo"/>
<property name="base-files" value="include"/>
<!-- Original manifest.mf file before filtering. -->
<property name="manifest.src" value="bingo/build/manifest.mf"/>
<!-- Some targets needs a more precise stem. -->
<property name="BSTEM" value="${java.source.dir}/${stem}"/>
<property name="tomcat.dir" value="c:/Apache/Tomcat"/>
<property name="webapp.dir" value="${tomcat.dir}/webapps/ROOT/WEB-INF/classes"/>
<!--List all Package used in this project -->
<property name="PackageList" value="
com.bingo,
com.bingo.database,
com.bingo.dbocw,
com.bingo.util,
com.bingo.taglibs.jndi,
com.bingo.finance.database,
com.bingo.finance.entity,
com.bingo.finance.manager"
/>
<!--你的project中所有的包-->
<!-- List all jar or file used in this project -->
<property name="classpath" value="${classpath};
${base-files}/tomcat/servlet.jar;
${base-files}/tomcat/webserver.jar;
${base-files}/log4j/log4j.jar;
${base-files}/log4j/log4j-core.jar"
/>
<!--你需要用到的包-->
<target name="init">
<tstamp />
</target>
<target name="build" depends="init">
<echo>
Building...
</echo>
<mkdir dir="${javac.dest}" />
<javac srcdir="${java.source.dir}"
destdir="${javac.dest}"
classpath="${classpath}"
debug="on"/>
</target>
<!-- ================================================================= -->
<!-- Copy class files to tomcat dir. -->
<!-- ================================================================= -->
<target name="copy" depends="build">
<copy todir="${webapp.dir}/com/bingo">
<fileset dir="${javac.dest}/com/bingo">
<include name="*.class"/>
</fileset>
</copy>
<copy todir="${webapp.dir}/com/bingo/util">
<fileset dir="${javac.dest}/com/bingo/util">
<include name="*.class"/>
</fileset>
</copy>
<copy todir="${webapp.dir}/com/bingo/database">
<fileset dir="${javac.dest}/com/bingo/database">
<include name="*.class"/>
</fileset>
</copy>
<copy todir="${webapp.dir}/com/bingo/dbocw">
<fileset dir="${javac.dest}/com/bingo/dbocw">
<include name="*.class"/>
</fileset>
</copy>
<copy todir="${webapp.dir}/com/bingo/finance/database">
<fileset dir="${javac.dest}/com/bingo/finance/database">
<include name="*.class"/>
</fileset>
</copy>
<copy todir="${webapp.dir}/com/bingo/finance/entity">
<fileset dir="${javac.dest}/com/bingo/finance/entity">
<include name="*.class"/>
</fileset>
</copy>
<copy todir="${webapp.dir}/com/bingo/finance/manager">
<fileset dir="${javac.dest}/com/bingo/finance/manager">
<include name="*.class"/>
</fileset>
</copy>
</target>
<!-- ================================================================= -->
<!-- Remove all generated (compiled) class files. -->
<!-- ================================================================= -->
<target name="clean" depends="init">
<delete dir="${javac.dest}/" />
</target>
<!-- ================================================================= -->
<!-- Remove all backup files. -->
<!-- ================================================================= -->
<target name="delete" depends="init">
<delete >
<fileset dir="${java.source.dir}/com/bingo">
<include name="*.bak"/>
</fileset>
</delete>
<delete >
<fileset dir="${java.source.dir}/com/bingo/util">
<include name="*.bak"/>
</fileset>
</delete>
<delete >
<fileset dir="${java.source.dir}/com/bingo/database">
<include name="*.bak"/>
</fileset>
</delete>
<delete >
<fileset dir="${java.source.dir}/com/bingo/finance/database">
<include name="*.bak"/>
</fileset>
</delete>
<delete >
<fileset dir="${java.source.dir}/com/bingo/finance/entity">
<include name="*.bak"/>
</fileset>
</delete>
<delete >
<fileset dir="${java.source.dir}/com/bingo/finance/manager">
<include name="*.bak"/>
</fileset>
</delete>
</target>
<!-- ================================================================= -->
<!-- Remove the temporary manifest file, actual work is done in the -->
<!-- dependencies. -->
<!-- ================================================================= -->
<target name="prejar" depends="build">
<mkdir dir="${jar.dest}"/>
<filter token="version" value="${version}" />
<copy file="${manifest.src}" tofile="${jar.dest}/manifest.mf"
filtering="true"/>
</target>
<!-- ================================================================= -->
<!-- This target Create bingo.jar -->
<!-- ================================================================= -->
<target name="jar" depends="prejar">
<delete file="${jar.dest}/bingo.jar"/>
<jar jarfile="${jar.dest}/bingo.jar" basedir="${javac.dest}"
manifest="${jar.dest}/manifest.mf"
/>
</target>
<!-- ================================================================= -->
<!-- This target builds the javadoc files. -->
<!-- ================================================================= -->
<target name="javadoc" depends="build,init">
<mkdir dir="${javadoc.dest}" />
<javadoc sourcepath="${java.source.dir}"
destdir="${javadoc.dest}"
classpath="${classpath}"
packagenames="${PackageList}"
version="true"
protected="true"
author="true"
use="true"
windowtitle="Bingo Free Java Code Version ${version}"
header="Bingo Free Java Code${version}"
/>
</target>
</project>
ant jakarta is a compilation tools, if you understand makefile under linux / Unix you can easily understand the use of the ant. ant is best for you to use UltraEdit (EditPlus) to write java program, and then you use ant to compile, and javadoc, generated a jar, war, realize copy files can be achieved through different tager go in build.xml, it is still very convenient a stuff is strongly recommended to use.
Two: download
you can download from the following address to the ant, the current version: 1.41
http://jakarta.apache.org/builds/jakarta-ant/release/v1.4.1/bin/
Three: Installation
A:) Windows
1: unzip the file you download, there will be a jakarta-ant directory (version number) to produce, he renamed Ant
2: Copy Ant directory to where you want.
3: Add the environment variable: ANT_HOME = ant installation directory, path and Canada $ ANT_HOME $ \ in; note that you must also have installed jdk, and add the JAVA_HOME environment variable, while early path added a $ JAVA_HOME $ \ in;
b:) Linux / Unix
1: unzip the file you downloaded, there will be a jakarta-ant directory (version number) to produce, he renamed Ant
2: Copy Ant directory to where you want.
3: Add the environment variable: ANT_HOME = ant installation directory, path and Canada $ ANT_HOME $ \ in; note that you must also have installed jdk, and add the JAVA_HOME environment variable, while early path added a $ JAVA_HOME $ \ in; to achieve modify environment variables you need to modify the .bash_profile file.
Following
the ANT_HOME = / usr / local / Ant
the JAVA_HOME = / usr / local / JDK
the PATH = $ the PATH: $ the HOME / bin: / usr / local / Ant / bin: / usr / local / JDK / bin
Export the PATH the ANT_HOME the JAVA_HOME
IV: write build.xml
build.xml quite Linux makefile under specific implementation are implemented in the build.xml.
I'll give an example to illustrate this point.
the build.xml
=============================================== =================
<Project name = "Bingo" default = "Build" basedir = "../ ..">
<-! basedir set the working directory - >
<Property name = "Version" value = "1.0" />
<!-- The base directory relative to which most targets are built -->
<property name="base" value="."/>
<!-- The directory where source files are stored. -->
<property name="java.source.dir" value="bingo/src"/>
<!--代码保存路径-->
<!-- Destination for compiled files -->
<property name="javac.dest" value="bingo/classes"/>
<!--class保存路径-->
<!-- Destination for generated jar files -->
<property name="jar.dest" value="bingo/jar"/>
<!--jar文件保存路径-->
<!-- Destination for documentation files generated or not -->
<name = Property "docs" value = "Bingo / docs" />
<-! javadoc file path ->
<!-- Destination for javadoc generated files -->
<property name="javadoc.dest" value="bingo/docs"/>
<!-- The stem where most log4j source code is located. -->
<property name="stem" value="com/bingo"/>
<property name="base-files" value="include"/>
<!-- Original manifest.mf file before filtering. -->
<property name="manifest.src" value="bingo/build/manifest.mf"/>
<!-- Some targets needs a more precise stem. -->
<property name="BSTEM" value="${java.source.dir}/${stem}"/>
<property name="tomcat.dir" value="c:/Apache/Tomcat"/>
<property name="webapp.dir" value="${tomcat.dir}/webapps/ROOT/WEB-INF/classes"/>
<!--List all Package used in this project -->
<property name="PackageList" value="
com.bingo,
com.bingo.database,
com.bingo.dbocw,
com.bingo.util,
com.bingo.taglibs.jndi,
com.bingo.finance.database,
com.bingo.finance.entity,
com.bingo.finance.manager"
/>
<!--你的project中所有的包-->
<!-- List all jar or file used in this project -->
<property name="classpath" value="${classpath};
${base-files}/tomcat/servlet.jar;
${base-files}/tomcat/webserver.jar;
${base-files}/log4j/log4j.jar;
${base-files}/log4j/log4j-core.jar"
/>
<!--你需要用到的包-->
<target name="init">
<tstamp />
</target>
<target name="build" depends="init">
<echo>
Building...
</echo>
<mkdir dir="${javac.dest}" />
<javac srcdir="${java.source.dir}"
destdir="${javac.dest}"
classpath="${classpath}"
debug="on"/>
</target>
<!-- ================================================================= -->
<!-- Copy class files to tomcat dir. -->
<!-- ================================================================= -->
<target name="copy" depends="build">
<copy todir="${webapp.dir}/com/bingo">
<fileset dir="${javac.dest}/com/bingo">
<include name="*.class"/>
</fileset>
</copy>
<copy todir="${webapp.dir}/com/bingo/util">
<fileset dir="${javac.dest}/com/bingo/util">
<include name="*.class"/>
</fileset>
</copy>
<copy todir="${webapp.dir}/com/bingo/database">
<fileset dir="${javac.dest}/com/bingo/database">
<include name="*.class"/>
</fileset>
</copy>
<copy todir="${webapp.dir}/com/bingo/dbocw">
<fileset dir="${javac.dest}/com/bingo/dbocw">
<include name="*.class"/>
</fileset>
</copy>
<copy todir="${webapp.dir}/com/bingo/finance/database">
<fileset dir="${javac.dest}/com/bingo/finance/database">
<include name="*.class"/>
</fileset>
</copy>
<copy todir="${webapp.dir}/com/bingo/finance/entity">
<fileset dir="${javac.dest}/com/bingo/finance/entity">
<include name="*.class"/>
</fileset>
</copy>
<copy todir="${webapp.dir}/com/bingo/finance/manager">
<fileset dir="${javac.dest}/com/bingo/finance/manager">
<include name="*.class"/>
</fileset>
</copy>
</target>
<!-- ================================================================= -->
<!-- Remove all generated (compiled) class files. -->
<!-- ================================================================= -->
<target name="clean" depends="init">
<delete dir="${javac.dest}/" />
</target>
<!-- ================================================================= -->
<!-- Remove all backup files. -->
<!-- ================================================================= -->
<target name="delete" depends="init">
<delete >
<fileset dir="${java.source.dir}/com/bingo">
<include name="*.bak"/>
</fileset>
</delete>
<delete >
<fileset dir="${java.source.dir}/com/bingo/util">
<include name="*.bak"/>
</fileset>
</delete>
<delete >
<fileset dir="${java.source.dir}/com/bingo/database">
<include name="*.bak"/>
</fileset>
</delete>
<delete >
<fileset dir="${java.source.dir}/com/bingo/finance/database">
<include name="*.bak"/>
</fileset>
</delete>
<delete >
<fileset dir="${java.source.dir}/com/bingo/finance/entity">
<include name="*.bak"/>
</fileset>
</delete>
<delete >
<fileset dir="${java.source.dir}/com/bingo/finance/manager">
<include name="*.bak"/>
</fileset>
</delete>
</target>
<!-- ================================================================= -->
<!-- Remove the temporary manifest file, actual work is done in the -->
<!-- dependencies. -->
<!-- ================================================================= -->
<target name="prejar" depends="build">
<mkdir dir="${jar.dest}"/>
<filter token="version" value="${version}" />
<copy file="${manifest.src}" tofile="${jar.dest}/manifest.mf"
filtering="true"/>
</target>
<!-- ================================================================= -->
<!-- This target Create bingo.jar -->
<!-- ================================================================= -->
<target name="jar" depends="prejar">
<delete file="${jar.dest}/bingo.jar"/>
<jar jarfile="${jar.dest}/bingo.jar" basedir="${javac.dest}"
manifest="${jar.dest}/manifest.mf"
/>
</target>
<!-- ================================================================= -->
<!-- This target builds the javadoc files. -->
<!-- ================================================================= -->
<target name="javadoc" depends="build,init">
<mkdir dir="${javadoc.dest}" />
<javadoc sourcepath="${java.source.dir}"
destdir="${javadoc.dest}"
classpath="${classpath}"
packagenames="${PackageList}"
version="true"
protected="true"
author="true"
use="true"
windowtitle="Bingo Free Java Code Version ${version}"
header="Bingo Free Java Code${version}"
/>
</target>
</project>
Reproduced in: https: //www.cnblogs.com/licheng/archive/2008/11/04/1326342.html