`
zhangljerry
  • 浏览: 144372 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

build.xml

    博客分类:
  • ant
阅读更多
The build.xml file is to Ant what a makefile is to make.
Althoug build.xml is an xml file, there is no dtd nor a schema to validate it! The document, however, must be well formed.
Ant can be instructed to use a differently named build.xml file by using the -f option.

Sample build.xml

<project name="name of project" default="compile" basedir=".">

  <property file="build.properties"/>
  <property file="${user.home}/build.properties"/>

  <property name="app.name"      value="myapp"/>
  <property name="app.path"      value="/${app.name}"/>
  <property name="app.version"   value="0.1-dev"/>
  <property name="build.home"    value="${basedir}/build"/>
  <property name="catalina.home" value="../../../.."/> <!-- UPDATE THIS! -->
  <property name="dist.home"     value="${basedir}/dist"/>
  <property name="docs.home"     value="${basedir}/docs"/>
  <property name="manager.url"   value="http://localhost:8080/manager"/>
  <property name="src.home"      value="${basedir}/src"/>
  <property name="web.home"      value="${basedir}/web"/>

  <taskdef name="deploy"   classname="org.apache.catalina.ant.DeployTask"/>
  <taskdef name="list"     classname="org.apache.catalina.ant.ListTask"/>
  <taskdef name="reload"   classname="org.apache.catalina.ant.ReloadTask"/>
  <taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask"/>
  
  <property name="compile.debug"       value="true"/>
  <property name="compile.deprecation" value="false"/>
  <property name="compile.optimize"    value="true"/>

  <property name="compile.debug"       value="true"/>
  <property name="compile.deprecation" value="false"/>
  <property name="compile.optimize"    value="true"/>

  <path id="compile.classpath">

    <pathelement location="${catalina.home}/common/classes"/>

    <fileset dir="${catalina.home}/common/endorsed">
      <include name="*.jar"/>
    </fileset>

    <fileset dir="${catalina.home}/common/lib">
      <include name="*.jar"/>
    </fileset>

    <pathelement location="${catalina.home}/shared/classes"/>

    <fileset dir="${catalina.home}/shared/lib">
      <include name="*.jar"/>
    </fileset>

  </path>

  <target name="all" depends="clean,compile"
   description="Clean build and dist directories, then compile"/>

  <target name="clean"
   description="Delete old build and dist directories">
    <delete dir="${build.home}"/>
    <delete dir="${dist.home}"/>
  </target>

  <target name="compile" depends="prepare"
   description="Compile Java sources">

    <!-- Compile Java classes as necessary -->
    <mkdir    dir="${build.home}/WEB-INF/classes"/>
    <javac srcdir="${src.home}"
          destdir="${build.home}/WEB-INF/classes"
            debug="${compile.debug}"
      deprecation="${compile.deprecation}"
         optimize="${compile.optimize}">
        <classpath refid="compile.classpath"/>
    </javac>

    <!-- Copy application resources -->
    <copy  todir="${build.home}/WEB-INF/classes">
      <fileset dir="${src.home}" excludes="**/*.java"/>
    </copy>
  </target>

  <target name="dist" depends="compile,javadoc"
   description="Create binary distribution">

    <!-- Copy documentation subdirectories -->
    <mkdir   dir="${dist.home}/docs"/>
    <copy    todir="${dist.home}/docs">
      <fileset dir="${docs.home}"/>
    </copy>

    <!-- Create application JAR file -->
    <jar jarfile="${dist.home}/${app.name}-${app.version}.war"
         basedir="${build.home}"/>

    <!-- Copy additional files to ${dist.home} as necessary -->

  </target>

  <target name="install" depends="compile"
   description="Install application to servlet container">

    <deploy url="${manager.url}"
       username="${manager.username}"
       password="${manager.password}"
           path="${app.path}"
       localWar="file://${build.home}"/>

  </target>

  <target name="javadoc" depends="compile"
   description="Create Javadoc API documentation">

    <mkdir          dir="${dist.home}/docs/api"/>
    <javadoc sourcepath="${src.home}"
                destdir="${dist.home}/docs/api"
           packagenames="*">
      <classpath refid="compile.classpath"/>
    </javadoc>

  </target>

  <target name="list"
   description="List installed applications on servlet container">

    <list    url="${manager.url}"
        username="${manager.username}"
        password="${manager.password}"/>

  </target>

  <target name="prepare">

    <!-- Create build directories as needed -->
    <mkdir  dir="${build.home}"/>
    <mkdir  dir="${build.home}/WEB-INF"/>
    <mkdir  dir="${build.home}/WEB-INF/classes"/>

    <!-- Copy static content of this web application -->
    <copy todir="${build.home}">
      <fileset dir="${web.home}"/>
    </copy>

    <!-- Copy external dependencies as required -->
    <!-- *** CUSTOMIZE HERE AS REQUIRED BY YOUR APPLICATION *** -->
    <mkdir  dir="${build.home}/WEB-INF/lib"/>
<!--
    <copy todir="${build.home}/WEB-INF/lib" file="${foo.jar}"/>
-->

    <!-- Copy static files from external dependencies as needed -->
    <!-- *** CUSTOMIZE HERE AS REQUIRED BY YOUR APPLICATION *** -->

  </target>

</project>

Tags

A build.xml file can contain the following tags:

project

The project tag is the root element of the build.xml file.
It can contain the following attributes:

name

This attribute names the project.

default

This attribute specifies the default target. That is, the target to be run if none is specified on the command line.

basedir

This attribute specifies the base directory that is used to construct absolute paths from relative paths.
basedir behaves like a property: it can be overriden on the command line:
ant -Dbasedir=c:\foo\bar

target

A target names a set of tasks that are executed when this target is run. A default target can be specified with the default attribute in the project element.
The following attributes can be specified:

name

Specifies the name of this target. In order to invoke a target, use this name on the command line:
ant name-of-target
This attribute is required.

default

???

if

The name of a property that must be set in order for a target to be executed. Consider the following file:
target_if
<project default="print_something">

  <target name="print_something" if="print_it">
    <echo message="print_it was set" />
  </target>
</project>
Just anting it:
ant -f target_if.xml
prints
Buildfile: target_if.xml

print_something:

BUILD SUCCESSFUL
Total time: 0 seconds
If, however, the property print_it is set:
ant -f target_if.xml -Dprint_it=1
Buildfile: target_if.xml

print_something:
     [echo] print_it was set

BUILD SUCCESSFUL
Total time: 0 seconds

depends

Lists (comma seperated) all targets on which this target depends. That is, it first makes all other targets (if necessary) before it makes this target.

description

????

javac

Invokes the java compiler (javac).
The following attributes can be specified:

srcdir

destdir

debug

deprecation

optimize

classpath

This element can occur within <javac> or <javadoc>
The following attributes can be specified:

refid

property

file

name

value

path

id

pathelement

location

fileset

dir

copy

todir

mkdir

dir

echo

Prints a message to the console.

message

Specifies the message to be printed.
echo.xml
<project default="print_something">
  <target name="print_something">
    <echo message="Here's a secret message" />
  </target>
</project>
If this file (named echo.xml) is invoked with Ant, it prints:
Buildfile: echo.xml

print_something:
     [echo] Here's a secret message

BUILD SUCCESSFUL
Total time: 0 seconds
A property's value can be echoed by placing like so:
echo_property.xml
<project default="print_something">

  <property name="foo" value="bar"/>

  <target name="print_something">
    <echo message="The value of foo is ${foo}" />
  </target>
</project>
Now, ant'ing this file:
ant -f echo_property.xml
Buildfile: echo_property.xml

print_something:
     [echo] The value of foo is bar

BUILD SUCCESSFUL
Total time: 0 seconds
echo_property.xml can be used to demonstrate the effect of ant's -D option:
ant -f echo_property.xml -Dfoo="overriding bar's default"
Buildfile: echo_property.xml

print_something:
     [echo] The value of foo is overriding bar's default

BUILD SUCCESSFUL
Total time: 0 seconds

javadoc

The following attributes can be specified:

sourcepath

destdir

packagenames

taskdef

name

????

classname

????
分享到:
评论

相关推荐

    ant的build.xml模板

    《Ant的build.xml模板详解与应用》 在软件开发领域,构建工具是不可或缺的一部分,它帮助开发者自动化地完成编译、测试、打包等任务。Apache Ant作为Java领域的一款经典构建工具,以其灵活性和强大的功能深受广大...

    一个常用的ant的build.xml

    Ant是基于XML的,它的核心在于`build.xml`文件,这个文件是项目的构建脚本,详细定义了构建过程中的各种任务和依赖关系。 标题“一个常用的ant的build.xml”暗示了我们讨论的是一个标准且常见的Ant构建配置文件。...

    Java build.xml打包文件

    java项目打包build.xml文件 ant打包

    build.xml详解

    ### build.xml详解 #### 概述 `build.xml` 是 Apache Ant 构建工具的核心配置文件,用于自动化软件构建过程中的各种任务。本篇将基于提供的 `build.xml` 文件示例,详细介绍其结构、语法以及如何通过配置实现自动化...

    ant build.xml 详解

    《Ant build.xml详解——构建Java项目的关键》 Apache Ant,作为一个开源的自动化构建工具,是Java开发者不可或缺的利器。它的核心在于一个名为`build.xml`的配置文件,它定义了项目的构建过程,包括编译、测试、...

    Jmeter+ant实现测试报告build.xml和报告模板jmeter-results-newreport.xsl

    3. **build.xml文件详解**:`build.xml`是Ant的构建文件,其中包含了一系列的任务和目标。例如,你可以定义一个目标来启动JMeter,另一个目标来生成测试报告,甚至还有一个目标用来发送测试结果的邮件通知。在描述中...

    build.xml 手写自动生成Hibernate映射文件和配置文件源代码

    build.xml 手写自动生成Hibernate映射文件和配置文件源代码

    ant build.xml 使用实例

    Apache Ant 是一个广泛使用的Java构建工具,它以XML格式定义构建脚本,即`build.xml`文件。这个文件包含了构建项目的整个流程,从编译源代码到生成最终的可执行或部署包。下面我们将深入探讨`build.xml`的使用以及...

    项目build.xml文件

    本文将深入探讨“项目build.xml文件”,这是一个与Ant构建工具密切相关的文件,用于规范Java项目的构建过程。 Ant是Apache软件基金会的一个开源项目,它是一个基于Java的构建工具,类似于Unix下的Make工具,但更为...

    ant build.xml编写

    《Ant build.xml构建详解》 在软件开发过程中,构建工具起着至关重要的作用,它能够自动化执行编译、测试、打包等任务。Apache Ant是Java领域广泛应用的一个构建工具,其核心在于一个名为`build.xml`的配置文件。...

    ant编译java web的build.xml文件

    《Ant构建Java Web应用:深度解析build.xml》 在软件开发过程中,自动化构建工具起着至关重要的作用,它们能够帮助开发者高效地管理项目,确保代码的编译、测试和部署等流程的一致性和可靠性。Apache Ant是Java领域...

    jmeter+ant 持续集成build.xml文件

    jmeter+ant 持续集成build.xml文件,直接使用ant命令执行jmeter脚本文件,得到图形测试报告

    ant打包sdk中build.xml

    首先,我们要了解`build.xml`文件。它是Ant的核心文件,包含了构建过程的配置和指令。这个文件使用XML格式编写,定义了各种任务(targets),每个任务包含了具体的构建步骤。例如,`clean`任务用于清理项目输出,`...

    Ant_的最完整build.xml解释,Ant入门与进阶

    《Ant的最完整build.xml解释:Ant入门与进阶》 Ant,作为Java世界中的一个构建工具,由Apache软件基金会开发,是项目管理和自动化构建的重要工具。它通过XML定义的build.xml文件,来描述项目的构建过程,包括编译、...

    ant 较完整的build.xml解释

    ### ant 较完整的build.xml解释 #### 一、Ant简介及优势 Ant 是一款开源的构建工具,主要用于Java项目的构建和部署。与传统的构建工具如Make相比,Ant具有诸多优势,尤其是在跨平台方面表现突出。Ant的核心优势...

    ANT-build.xml命令详解

    **ANT-build.xml命令详解** Apache Ant 是一个Java平台上的开源构建工具,它通过XML格式的配置文件(如`build.xml`)来定义构建任务。Ant的设计理念是“简单就是美”,它使得Java项目的构建过程变得可配置且易于...

    ant的配置文件build.xml

    在Ant的世界中,`build.xml`是核心配置文件,它包含了项目构建的所有指令和任务。这篇内容将深入解析`build.xml`文件的结构、元素以及如何使用它来管理Java项目的构建过程。 一、`build.xml`文件结构 `build.xml`...

    ant build.xml文件详解

    Ant build.xml 文件详解 Ant 是一个项目管理工具,相比make命令,gnumake和nmake等编译工具,Ant克服了这些工具的缺陷。Ant 的优点包括跨平台性、操作简单、易于集成到开发环境中。Ant 的构建文件是 XML 格式的文件...

    build.xml文件

    构建自动化测试平台的时候需要新建的build.xml文件

Global site tag (gtag.js) - Google Analytics