项目中,使用ant,最基本的build.xml文件的书写方式

本文介绍了一个使用Apache Ant构建工具的基本示例,展示了如何通过build.xml文件配置编译、打包等任务,实现Java项目的自动化构建过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目中,最简单的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> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值