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
相关文章
- java基础知识回顾之javaIO类--File类应用:过滤器接口FilenameFilter和FileFilter
- Java IO--File类
- Python学习--17 访问数据库
- linux shell 脚本攻略学习13--file命令详解,diff命令详解
- Java12新特性 -- 默认生成类数据共享(CDS)归档文件
- J2EE--常见面试题总结 -- (二)
- 《android开发艺术探索》读书笔记(十一)--Android的线程和线程池
- 《Android源码设计模式》--装饰模式
- 小白学数据分析--回归分析在游戏人气分析的应用探索
- 使用私有Pod Spec的类库--提高公司开发效率
- JVM 调优实战--VisualVM综合分析可视化工具的使用教程(含远程JMX连接)
- 企业面试真题--010
- file encode - /UI2/CL_HTTP_FILE_ENCODE
- javascript arguments对象研究--针对jquery源码研究再研究
- 成功解决CondaError: Error reading file, file should be a text file containing packages conda create --he
- 成功解决Exception: Graph file doesn't exist, path=F:File_PythonPython_exampleHuman_Posture_Detection
- 已解决raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+‘; not supported’)
- guava学习--File
- Error: bad restore file magic number (file may be corrupted) -- no data loaded In addition: Warni
- 垂死挣扎还是涅槃重生 -- Delphi XE5 公布会归来感想
- 龙芯软件开发(33)-- USB协议深入分析
- 【计算机三级数据库技术】第1章 数据库应用系统生命周期下知识体系--附思维导图
- Mysql原理篇之redo日志--下--10
- a31.ansible 生产实战案例 -- 基于二进制包安装kubernetes v1.21 -- 集群升级(二)
- 我用过的设计模式(4)-- 责任链模式
- 打开我的收藏夹 -- Python时间序列分析篇