Sample Ant Build File - WAR--reference
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的更多相关文章
- 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 ...
- 【Ant】How to print all the system properties in Ant build file
在Ant里可以使用echoproperties task来达到目的 <target name="run"> <echoproperties /> </ ...
- jenkins之从0到1利用Git和Ant插件打war包并自动部署到tomcat(第五话):总结以及build.xml文件
前面基本上把整个配置过程都完整地串起来了,包括可能遇到的难点,按照那个套路应该可以配置好自动打包发布的功能.简单总结下我的学习过程,以及遇到问题是怎样解决的. 准备一个项目源码 刚开始在github和 ...
- 自动构建War包的Ant build.xml模板
<?xml version="1.0" encoding="UTF-8" ?> <project name="[*****]你的项目 ...
- 一个完整的JENKINS下的ANT BUILD.XML文件(Jenkins可以参考)
一个完整的JENKINS下的ANT BUILD.XML文件 <?xml version="1.0" encoding="UTF-8"?> <p ...
- Ant build.xml
Ant的概念可能有些读者并不连接什么是Ant以及入可使用它,但只要使用通过Linux系统得读者,应该知道make这个命令.当编译Linux内核及一些软件的源程序时,经常要用这个命令.Make命令其实就 ...
- ant build打包
使用ant build进行增量打包 <?xml version="1.0" encoding="gb2312"?> <project name ...
- Java MyEclipse下Ant build.xml简单实例详解
一.下载配置ant 1.首先下载ant: http://www.apache.org/ 下载最新的版本2.解压ant 后设置ANT_HOME, PATH中添加ANT_HOME目录下的bin目录(如:A ...
- Java Ant build.xml详解
1,什么是antant是构建工具2,什么是构建概念到处可查到,形象来说,你要把代码从某个地方拿来,编译,再拷贝到某个地方去等等操作,当然不仅与此,但是主要用来干这个3,ant的好处跨平台 --因为 ...
随机推荐
- NOI2008 志愿者招募
1061: [Noi2008]志愿者招募 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 1859 Solved: 1169[Submit][Stat ...
- iOS开发中自定义字体的方法
http://www.cnblogs.com/iyou/archive/2014/05/25/3751669.html 1. 首先下载你想要设置的字体库,例如设置方正启体简体 2. 添加到工程,一定要 ...
- SharePoint Srver 2010 资源汇总
转:http://bbs.winos.cn/thread-93681-1-1.html Microsoft SharePoint Server 2010 是适用于企业和网络的业务协作平台,可以帮助您通 ...
- C#图片处理之: 另存为压缩质量可自己控制的JPEG
处理图片时常用的过程是:读入图片文件并转化为Bitmap -> 处理此Bitmap的每个点以得到需要的效果 -> 保存新的Bitmap到文件使用C#很方便的就可以把多种格式的图片文件读到B ...
- GIS数据格式:Geodatabase
转自:http://www.cnblogs.com/quansixiang/archive/2010/09/17/1829286.html 1 Geodatabase概念 Geodatabase是A ...
- 如何使一个网络下的2台路由器都可以dhcp上网
设备:2台路由器,网线若干 首先,设置好一个路由器,让它可以拨号上网.网关设置为192.168.1.1,子网掩码为255.255.255.0,dns为61.177.7.1 然后,设置第二台路由器.设置 ...
- SQL SERVER 2008查询其他数据库
1.访问本地的其他数据库 --启用Ad Hoc Distributed Queries-- reconfigure reconfigure -- 使用完成后,关闭Ad Hoc Distributed ...
- QTP自传之初识
我叫QTP,全名是HP Quicktest Professional,大家都叫我小Q. 小Q生于1998年,那是一个春天(哈哈咱也是跨世纪的人才).家里人丁兴旺,兄弟众多,L(Loadrunner), ...
- NOIP2002 均分纸牌
题一 均分纸牌 (存盘名: NOIPG1) [问题描述] 有 N 堆纸牌,编号分别为 1,2,…, N.每堆上有若干张,但纸牌总数必为 N 的倍数.可以在任一堆上取若于张纸牌,然后移动. 移牌规则为: ...
- HDU 1114 iggy-Bank(完全背包)
水 给出小猪钱罐的重量和装满钱后的重量,然后是几组数据,每组数据包括每种钱币的价值与重量 要求出重量最少能装满钱罐时的最大价值 #include<iostream> #include< ...