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. js 中var that=this

    js中经常出现var that=this,为什么这么做? http://stackoverflow.com/questions/4886632/what-does-var-that-this-mean ...

  2. MyBatis学习总结2

    这一篇讲述MyBatis对数据库的CRUD操作,内容不做重复,只做添加:查看学习总结1 一.使用MyBatis对表执行CRUD操作——基于XML的实现 在SQL映射文件userMapper.xml中添 ...

  3. 修改NGINX版本名称为任意WEB SERVER

    下载好Nginx的安装文件nginx-1.6.0.tar.gz,并把它解压. wget http://nginx.org/download/nginx-1.6.0.tar.gz .tar.gz 然后我 ...

  4. Android获取IMSI和IMEI

    IMSI是一个 唯一的数字, 标识了GSM和UMTS 网络里的唯一一个用户. 它 存储 在手机的SIM卡里,它会通过手机发送到网络上. IMEI也是一串唯一的数字, 标识了 GSM 和 UMTS网络里 ...

  5. [Jacky] 解决Ext.Net GridPanel 选择的行数据刷新后不能获取最新值

    选择GridPanel中一行数据,当变更数据时并重新刷新之后不能获取最新值,需通过如下方式获取: var internalId = gridPanel.getSelectionModel().getL ...

  6. [Raobin] Ext.net在多重子父窗体中找到当前窗体的父窗体,并关闭IFrame父窗体

    var closeParentWindow = function () { var currentWin = window; while (top != currentWin) { var prent ...

  7. Javascript检测浏览器对CSS属性的支持 /* supports */

    //检测浏览器对CSS属性的支持 supports = (function() { var div = document.createElement('div'), vendors = 'Khtml ...

  8. 【CSS3】Advanced3:Universal, Child, and Adjacent Selectors

    1.Universal selectors eg:#target*{ } 2.Child selectors < something immediately nested within some ...

  9. leecode 归并排序 链表(java)

    写了好久,终于写成了.第一次zai leecode错题,题目质量很高,适合面试,与 1.归并排序是稳定的,在java中 Arrays.sort(a);中对于对象的排序就是归并排序.对于原子类型数据使用 ...

  10. ftp两种传输方式区别

    转自:http://linux.chinaitlab.com/server/806269.html FTP可用多种格式传输文件,通常由系统决定,大多数系统(包括UNIX系统)只有两种模式:文本模 式和 ...