一个Java项目Ant实例

自己的Ant工程实例,以备参考,
build.xml:

xml 代码
 
xml 代码
 
  1. <xml version="1.0"?>  
  2. <!---->-- ======================================================================   
  3.      2006-8-3 9:54:33                                                          
  4.   
  5.      xxx     
  6.                      
  7.     xxx                                                                 
  8.      ====================================================================== -->  
  9. <project name="SHOTA2" default="usage" basedir=".">  
  10.     <description>  
  11.             xxx build  
  12.     </<!---->description>  
  13.   
  14.     <!---->-- =================================   
  15.           target: initial variable                
  16.          ================================= -->  
  17.     <target name="init" description="1--Set System protpeties  
  18.                                           2--Set FileSets  
  19.                                           3--Delete And Create Folders">  
  20.         <property file="${basedir}/build.properties" />  
  21.         <property name="Name" value="xxx project" />  
  22.         <property name="name" value="cmcc2" />  
  23.         <property name="version" value="0.2" />  
  24.         <property name="year" value="2003" />  
  25.   
  26.         <echo message="----------- ${Name} ${version} [${year}] ------------" />  
  27.   
  28.         <property name="debug" value="off" />  
  29.         <property name="optimize" value="on" />  
  30.         <property name="deprecation" value="on" />  
  31.   
  32.         <property name="src.dir" value="./src" />  
  33.         <property name="lib.dir" value="./lib" />  
  34.         <property name="packages" value="com.*,test.*" />  
  35.   
  36.         <property name="build.src" value="./build/src" />  
  37.         <property name="build.dest" value="./build/classes" />  
  38.         <property name="build.javadocs" value="./build/doc" />  
  39.   
  40.         <property name="dist" value="./dist" />  
  41.   
  42.         <path id="classpath">  
  43.             <pathelement path="${jsdk_jar}" />  
  44.             <fileset dir="${lib.dir}">  
  45.                 <include name="**/*.jar" />  
  46.                 <include name="**/*.zip" />  
  47.             <<!---->/fileset>  
  48.         <<!---->/path>  
  49.   
  50.         <filter token="year" value="${year}" />  
  51.         <filter token="version" value="${version}" />  
  52.         <filter token="date" value="${TODAY}" />  
  53.         <filter token="log" value="true" />  
  54.         <filter token="verbose" value="true" />  
  55.     <!----></target>  
  56.   
  57.     <!---->  
  58.     <!---->  
  59.     <!---->  
  60.     <target name="usage" depends="init">  
  61.         <echo message="${Name} Build file" />  
  62.         <echo message="-------------------------------------------------------------" />  
  63.         <echo message="" />  
  64.         <echo message=" available targets are:" />  
  65.         <echo message="" />  
  66.         <echo message="   jar      --> generates the ${name}.jar file" />  
  67.         <echo message="   build    --> compiles the source code" />  
  68.         <echo message="   javadoc  --> generates the API documentation" />  
  69.         <echo message="   clean    --> cleans up the directory" />  
  70.         <echo message="   dep      --> deploy the project jar to running place" />  
  71.         <echo message="   new_dep  --> building and deploy the project " />  
  72.         <echo message="   all      --> make all target" />  
  73.         <echo message="" />  
  74.         <echo message=" Please rename build.properties.default to build.properties" />  
  75.         <echo message=" and edit build.properties to specify JSDK 2.3 classpath." />  
  76.         <echo message="" />  
  77.         <echo message=" See the comments inside the build.xml file for more details." />  
  78.         <echo message="-------------------------------------------------------------" />  
  79.         <echo message="" />  
  80.         <echo message="" />  
  81.     </<!---->target>  
  82.   
  83.     <!---->  
  84.     <!---->  
  85.     <!---->  
  86.     <target name="prepare-src" depends="init">  
  87.         <!---->  
  88.         <mkdir dir="${build.src}" />  
  89.         <mkdir dir="${build.dest}" />  
  90.   
  91.         <!---->  
  92.         <copy todir="${build.src}/com">  
  93.             <fileset dir="${src.dir}/com">  
  94.                 <include name="**/*.java" />  
  95.             </<!---->fileset>  
  96.         </<!---->copy>  
  97.     <!----></target>  
  98.   
  99.     <!---->  
  100.     <!---->  
  101.     <!---->  
  102.     <target name="build" depends="prepare-src">  
  103.         <javac srcdir="${build.src}" fork="true" executable="${jsdk_path}/bin/javac" destdir="${build.dest}" debug="${debug}" optimize="${optimize}">  
  104.             <classpath refid="classpath" />  
  105.         </<!---->javac>  
  106.         <copy todir="${build.dest}/com">  
  107.             <fileset dir="${src.dir}/com">  
  108.                 <include name="**/*.xml" />  
  109.             <!----></fileset>  
  110.         <!----></copy>  
  111.     <!----></target>  
  112.   
  113.     <!---->  
  114.     <!---->  
  115.     <!---->  
  116.     <target name="jar" depends="build">  
  117.         <jar jarfile="${dist}/${name}.jar" basedir="${build.dest}" includes="**" />  
  118.     </<!---->target>  
  119.   
  120.     <!---->  
  121.     <!---->  
  122.     <!---->  
  123.     <target name="dep" depends="jar">  
  124.         <copy file="${dist}/${name}.jar" todir="${deploy_path}/cmcc2" overwrite="true" />  
  125.    </ <!---->target>  
  126.   
  127.     <!---->  
  128.     <!---->  
  129.     <!---->  
  130.     <target name="javadoc" depends="build">  
  131.         <mkdir dir="${build.javadocs}" />  
  132.         <javadoc packagenames="${packages}" sourcepath="${build.src}" destdir="${build.javadocs}" source="1.3" author="true" version="true" use="true" splitindex="true" windowtitle="${Name} API" doctitle="${Name}">  
  133.             <classpath refid="classpath" />  
  134.         <!----></javadoc>  
  135.     </<!---->target>  
  136.   
  137.     <!---->  
  138.     <!---->  
  139.     <!---->  
  140.     <target name="clean" depends="init">  
  141.         <delete dir="${build.src}" />  
  142.         <delete dir="${build.dest}/test" />  
  143.         <delete dir="${build.dest}/com" />  
  144.         <delete dir="${build.javadocs}" />  
  145.         <delete>  
  146.             <fileset dir="${dist}" includes="*.jar" />  
  147.         </<!---->delete>  
  148.     </<!---->target>  
  149.   
  150.     <!---->  
  151.     <!---->  
  152.     <!---->  
  153.     <target name="all" depends="clean,jar,javadoc,dep" description="Create all JAR files and create all target" />  
  154.       
  155.     <!---->  
  156.     <!---->  
  157.     <!---->  
  158.     <target name="new_dep" depends="clean,dep" description="Create all JAR files and create all target" />  
  159. </project>  


       build.properties:
java 代码
 
  1. #Created by JInto - www.guh-software.de  
  2. #Wed Jan 31 13:32:14 CST 2007  
  3. jsdk_path = D:/tools/jdk1.3.1  
  4. deploy_path = d:/23/lib/internal/  

你可能感兴趣的:(java,xml,ant,UP)