Use of Jakarta-ant (Java Compilation tool)

Source: Internet
Author: User
Tags file copy include mkdir modify variable tomcat log4j linux
Compile One: Introduction:
Ant is a compilation tool for Jakarta, and if you understand the makefile under Linux/unix you'll be very easy to
Understand the use of ant. Ant is best for you to use UltraEdit (EditPlus) to write Java programs, and then you use ant to compile, and Javadoc, to generate a Jar,war, The implementation of the file copy can be in Build.xml through different tager to achieve, or very convenient one Dongdong strongly recommended is to use.
Two: Download
You can download from the address below to ant, 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 downloaded, there will be a jakarta-ant (version number) directory generated, renamed him Ant
2:copy ant directory to the location you want.
3: Add in environment variable: Ant_home=ant installation directory, add $ant_home$\in in path; Note that you must also have the JDK installed and add the JAVA_HOME environment variable, plus $java_home$\in in the early path;

B:) Linux/unix
1: Unzip the file you downloaded, there will be a jakarta-ant (version number) directory generated, renamed him Ant
2:copy ant directory to the location you want.
3: Add in environment variable: Ant_home=ant installation directory, add $ant_home$\in in path; Note that you must also have the JDK installed and add the JAVA_HOME environment variable, plus $java_home$\in in the early path; Implement modify environment variable you need to modify the. bash_profile file.
As follows
Ant_home=/usr/local/ant
Java_home=/usr/local/jdk
Path= $PATH: $HOME/bin:/usr/local/ant/bin:/usr/local/jdk/bin

Export PATH ant_home Java_home

IV: Writing Build.xml
Build.xml rather Linux under the makefile, the implementation of the specific in Build.xml.
Let me give an example to illustrate.
Build.xml
================================================================
<project name= "Bingo" default= "Build" basedir= ". /.. ">
<!--basedir set 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"/>
<!--code save path-->
<!--destination for compiled files-->
<property name= "Javac.dest" value= "bingo/classes"/>
<!--class Save path-->
<!--destination for generated jar files-->
<property name= "Jar.dest" value= "Bingo/jar"/>
<!--jar File save path-->
<!--destination for documentation files generated or not-->
<property name= "Docs" value= "Bingo/docs"/>
<!--Javadoc File save 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 "
/>
<!--all the packages in your project-->
<!--List all jars 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 "

/>
<!--you need to use the bag-->
<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 do 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>



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.