I am using the Spring SimpleFormController example to illustrate the build process. The figure below shows the structure of the web application.

All the classes inside the src directory should be compiled and placed in a separate build/classesdirectory. The created war file will be placed inside the dist directory.

So first we create the build/classes and the dist directory. The init target does this job.

1.<target name="init">
2.<mkdir dir="build/classes"/>
3.<mkdir dir="dist" />
4.</target>

The next step is to compile all the classes in the src directory and place them in the build/classesdirectory. To do this first you need to add all the lib files inside the "WebContent/WEB-INF/lib" directory to the classpath.

1.<path id="compile.classpath">
2.<fileset dir="WebContent/WEB-INF/lib">
3.<include name="*.jar"/>
4.</fileset>
5.</path>

The target compile uses the javac task to compile the java classes and it depends on the target init, because only when you have the directory ready you can place the classes inside them.

1.<target name="compile" depends="init" >
2.<javac destdir="build/classes" debug="true" srcdir="src">
3.<classpath refid="compile.classpath"/>
4.</javac>
5.</target>

The path we created earlier will be refered here using the <classpath> element.

Now we can create the war file using the war task. To create the war file you need to specify the web directory, lib directory and the classes directory. The destfile attribute specifies the war file location and the webxml attribute specifies the web.xml file location.

1.<target name="war" depends="compile">
2.<war destfile="dist/AntExample.war" webxml="WebContent/WEB-INF/web.xml">
3.<fileset dir="WebContent"/>
4.<lib dir="WebContent/WEB-INF/lib"/>
5.<classes dir="build/classes"/>
6.</war>
7.</target>

You can use the clean target to clean the project. The clean target deletes the build and the dist directory.

1.<target name="clean">
2.<delete dir="dist" />
3.<delete dir="build" />
4.</target>

The complete build.xml file is shown below.

<?xml version="1.0" ?>
<project name="AntExample1" default="war"> <path id="compile.classpath">
<fileset dir="WebContent/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
</path> <target name="init">
<mkdir dir="build/classes"/>
<mkdir dir="dist" />
</target> <target name="compile" depends="init" >
<javac destdir="build/classes" debug="true" srcdir="src">
<classpath refid="compile.classpath"/>
</javac>
</target> <target name="war" depends="compile">
<war destfile="dist/AntExample.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent"/>
<lib dir="WebContent/WEB-INF/lib"/>
<classes dir="build/classes"/>
</war>
</target> <target name="clean">
<delete dir="dist" />
<delete dir="build" />
</target> </project>

reference from:http://www.dzone.com/tutorials/java/ant/ant-sample-build-file-war-1.html

Sample Ant Build File - WAR--reference的更多相关文章

  1. Gradle Goodness: Rename Ant Task Names When Importing Ant Build File

    Migrating from Ant to Gradle is very easy with the importBuild method from AntBuilder. We only have ...

  2. 【Ant】How to print all the system properties in Ant build file

    在Ant里可以使用echoproperties task来达到目的 <target name="run"> <echoproperties /> </ ...

  3. jenkins之从0到1利用Git和Ant插件打war包并自动部署到tomcat(第五话):总结以及build.xml文件

    前面基本上把整个配置过程都完整地串起来了,包括可能遇到的难点,按照那个套路应该可以配置好自动打包发布的功能.简单总结下我的学习过程,以及遇到问题是怎样解决的. 准备一个项目源码 刚开始在github和 ...

  4. 自动构建War包的Ant build.xml模板

    <?xml version="1.0" encoding="UTF-8" ?> <project name="[*****]你的项目 ...

  5. 一个完整的JENKINS下的ANT BUILD.XML文件(Jenkins可以参考)

    一个完整的JENKINS下的ANT BUILD.XML文件 <?xml version="1.0" encoding="UTF-8"?> <p ...

  6. Ant build.xml

    Ant的概念可能有些读者并不连接什么是Ant以及入可使用它,但只要使用通过Linux系统得读者,应该知道make这个命令.当编译Linux内核及一些软件的源程序时,经常要用这个命令.Make命令其实就 ...

  7. ant build打包

    使用ant build进行增量打包 <?xml version="1.0" encoding="gb2312"?> <project name ...

  8. Java MyEclipse下Ant build.xml简单实例详解

    一.下载配置ant 1.首先下载ant: http://www.apache.org/ 下载最新的版本2.解压ant 后设置ANT_HOME, PATH中添加ANT_HOME目录下的bin目录(如:A ...

  9. Java Ant build.xml详解

    1,什么是antant是构建工具2,什么是构建概念到处可查到,形象来说,你要把代码从某个地方拿来,编译,再拷贝到某个地方去等等操作,当然不仅与此,但是主要用来干这个3,ant的好处跨平台   --因为 ...

随机推荐

  1. linux设备驱动那点事儿之平台设备理论篇

    一:Platform总线 1.1概述 一个现实的linux设备驱动通常需要挂接在一种总线上,对于本身依附于PCI,USB,IIC,SPI等的设备而言,这自然不是问题,但是在嵌入式系统里面,SOC系统中 ...

  2. 【HDOJ】1225 Football Score

    这种结构体排序的题,十分容易考上机题,qsort+结构体解决.马上就要机考了,多练习一下这样的题目也好. #include <stdio.h> #include <string.h& ...

  3. Android开发UI之android:gravity / android:layout_Gravity,android:padding / android:layout_margin属性区分

    android:gravity / android:layout_Gravity区别: android:gravity 是设置该view里面的内容相对于该view的位置,例如设置button里面的te ...

  4. URAL1017. Staircases

    链接 简单递推 #include <iostream> #include<cstdio> #include<cstring> #include<algorit ...

  5. hadoop2.2编程:使用MapReduce编程实例(转)

    原文链接:http://www.cnblogs.com/xia520pi/archive/2012/06/04/2534533.html 从网上搜到的一篇hadoop的编程实例,对于初学者真是帮助太大 ...

  6. Microsoft Internet Explorer内存破坏漏洞(CVE-2013-5052)

    漏洞版本: Microsoft Internet Explorer 6-11 漏洞描述: BUGTRAQ ID: 64126 CVE(CAN) ID: CVE-2013-5052 Internet E ...

  7. 解决easyui和bootstrap兼容问题

    在使用bootstrap和easyui的时候,发现很多有冲突的地方,包括datagrid控件和combo等,以下进行的问题修正,保证easyui正常显示 /*bootstrap兼容问题和easyui的 ...

  8. HW5.5

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  9. CodeForces 540E - Infinite Inversions(离散化+树状数组)

    花了近5个小时,改的乱七八糟,终于A了. 一个无限数列,1,2,3,4,...,n....,给n个数对<i,j>把数列的i,j两个元素做交换.求交换后数列的逆序对数. 很容易想到离散化+树 ...

  10. mongodb的查询操作符

    本文地址:http://www.cnblogs.com/egger/archive/2013/05/04/3059374.html   欢迎转载 ,请保留此链接! 官方参考: http://docs. ...