項目中,使用ant,最基本的build.xml文件的書寫方式

項目中,最簡單的build.xml文件的書寫方式。
項目source目錄。

project
    - src
    - web
ant
    - ant.bat
    - bulid.xml
    - project.war (編譯出來的war 的位置)
====================================================================================================================================

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

<!--
  # $Id: build.xml,v 1.4 2005/11/17 07:25:33 luyang Exp $
  #
  # Copyright (C)  All Rights Reserved.
-->

<project name="Project Build" default="makewar" basedir=".">

 <!-- ========== Prerequisite Properties =========== -->
 <property file="./common.properties" />

 <!-- Set the properties for source directories -->
 <property name="src.all.dir" value="../project/src" />
 <property name="web.all.dir" value="../project/web" />

 <property name="src.output.dir" value="./dist/src" />
 <property name="web.output.dir" value="./dist/web" />

 <!-- Compile Libraries directory -->
 <property name="compile.lib.dir" value="${web.output.dir}/WEB-INF/lib" />
 <property name="compile.target.dir" value="${web.output.dir}/WEB-INF/classes" />

 <!-- Compilation Classpath -->
 <path id="compile.classpath">
  <fileset dir="${compile.lib.dir}">
   <include name="**/*.jar" />
  </fileset>
 </path>


 <!-- ========== Executable Targets ============== -->


 <!--
        The "init" target evaluates "available" expressions as necessary
        to modify the behavior of this script and print some information on
        screen
 -->
 <target name="init">
  <echo message="--------- ${project.name} ${project.version} ---------" />
  <echo message="" />
  <echo message="java.class.path = ${java.class.path}" />
  <echo message="java.home       = ${java.home}" />
  <echo message="user.home       = ${user.home}" />
  <tstamp>
   <format property="year" pattern="yyyy" />
   <format property="date" pattern="yyyy/MM/dd" />
  </tstamp>
 </target>

 <!-- Remove directory -->
 <target name="clean" depends="init" description="Delete old build and dist directories">
  <delete dir="${src.output.dir}" />
  <delete dir="${web.output.dir}" />
 </target>

 <!-- Create directory -->
 <target name="prepare" depends="init">
  <mkdir dir="${src.output.dir}" />
  <mkdir dir="${web.output.dir}" />
 </target>

 <!-- CopySource to output Directory -->
 <target name="copy" depends="prepare">
  <copy todir="${src.output.dir}">
   <fileset dir="${src.all.dir}" />
  </copy>
  <copy todir="${web.output.dir}">
   <fileset dir="${web.all.dir}" excludes="**/*.class" />
  </copy>

  <delete dir="${web.output.dir}/WEB-INF/classes" />
  <mkdir dir="${web.output.dir}/WEB-INF/classes" />
 </target>

 <!-- Compile -->
 <target name="compile" depends="copy" description="Compile sources">
  <javac destdir="${compile.target.dir}" srcdir="${src.output.dir}" source="1.4" target="1.4">
   <include name="**/*.java" />
   <classpath refid="compile.classpath" />
  </javac>

  <copy todir="${web.output.dir}/WEB-INF/classes">
   <fileset dir="${src.output.dir}" includes="**/*.properties" />
  </copy>
  <delete file="${web.output.dir}/WEB-INF/lib/servlet.jar" />
 </target>

 <!--Make War -->
 <target name="war" description="Make war">
  <jar destfile="./project.war" basedir="${web.output.dir}" />
 </target>

 <!-- Make Jar
    <target name="jar" description="Make jar"> <jar destfile="./project.jar"  basedir="${compile.target.dir}"/>
    </target>
    -->

 <target name="mkwar" depends="init, clean, prepare, copy, compile, war" />
</project> 

發佈了41 篇原創文章 · 獲贊 29 · 訪問量 21萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章