使用Ant构建struts2 web工程,自动编译,打包成war
c&c++语言通常使用make脚本来构建和管理自己的工程,同样java也有自己的构建工具(Ant),使用时需要写一个biuld.xml,有点类似c&c++里的makefile。
一、首先定义一些变量,如下,个人感觉有点类似makefile的写法
#==================== File and Directory Names ======================== app.name=AntDemo
app.version=0.1 source.home=./src
lib.home=./WebContent/WEB-INF/lib
lib.external=./lib_external
webapp.home=./WebContent
build.home=./build
dist.home=./dist #==================== Compilation Control Options ===================== compile.debug=true
compile.deprecation=false
compile.optimize=true
二、然后写几个target
一般就clean,init,Compile,Build,Archive,具体如下
<?xml version="1.0"?> <!-- ======================================================================
Date: June 2015 Project: Ant Demo Author: Peter Chen
====================================================================== --> <project name="AntDemo" default="archive" basedir="."> <description>
a project of using ant
</description> <property file="build.properties"/> <!-- ==================== Clean Target ==================================== --> <!--
删除之前工程构建时产生的临时文件
-->
<target name="clean" description="Delete old directories and files">
<delete dir="${dist.home}"/>
<delete dir="${build.home}"/>
<delete >
<fileset dir="${source.home}" includes="**/*.class"/>
</delete>
</target> <!-- ==================== Init Target ================================== --> <!--
新建build文件夹
-->
<target name="init" depends="clean" description="Create build directory"> <mkdir dir="${build.home}" /> </target> <!-- ==================== Compile Target ================================== --> <!--
编译源代码,将编译生成的class文件copy到${build.home}/WEB-INF/classes目录下
-->
<target name="compile" depends="init" description="Compile Java sources"> <mkdir dir="${build.home}/WEB-INF/classes" /> <javac srcdir="${source.home}"
destdir="${build.home}/WEB-INF/classes"
debug="${compile.debug}"
deprecation="${compile.deprecation}"
optimize="${compile.optimize}"
source="1.7" target="1.7" includeantruntime="on"> <classpath>
<path>
<fileset dir="${lib.home}" />
<fileset dir="${lib.external}" />
</path>
</classpath>
</javac> </target> <!-- ==================== Build Target ================================== --> <!--
把非class文件拷贝到build目录下
--> <target name="build" depends="compile" description="Copies all non Java classes to build directoy">
<copy todir="${build.home}">
<fileset dir="${webapp.home}" excludes="SVN,**/*.class" />
</copy>
<copy todir="${build.home}/WEB-INF/classes">
<fileset dir="${source.home}" excludes="SVN,**/*.java" />
</copy>
</target> <!-- ==================== Archive Target ================================== --> <!--
打包成war文件
--> <target name="archive" depends="build" description="Create binary archive of all files in dist.home"> <!-- Create war directory -->
<mkdir dir="${dist.home}" /> <!-- Create application WAR file -->
<jar jarfile="${dist.home}/${app.name}.war" basedir="${build.home}" /> </target> </project>
三、最后直接运行target即可
贴上demo的github地址:https://github.com/peterchenhdu/AntDemo/ ,
有兴趣的可以下载下来看看,一个基于struts2的web工程,使用ant自动编译打包成war。
使用Ant构建struts2 web工程,自动编译,打包成war的更多相关文章
- Ant自动编译打包&发布 android项目
Eclipse用起来虽然方便,但是编译打包android项目还是比较慢,尤其将应用打包发布到各个渠道时,用Eclipse手动打包各种渠道包就有点不切实际了,这时候我们用到Ant帮我们自动编译打包了. ...
- Andorid进阶7—— Ant自动编译打包&发布 android项目
http://www.cnblogs.com/tt_mc/p/3891546.html Eclipse用起来虽然方便,但是编译打包android项目还是比较慢,尤其将应用打包发布到各个渠道时,用Ecl ...
- Ant自动编译打包android项目(转载)
1.1 Ant安装 ant的安装比较简单,下载ant压缩包 http://ant.apache.org (最新的为1.9.3版本),下载之后将其解压到某个目录(本人解压到E:\Progra ...
- (转载)Ant自动编译打包android项目
1 Ant自动编译打包android项目 1.1 Ant安装 ant的安装比较简单,下载ant压缩包 http://ant.apache.org (最新的为1.9.3版本),下载之后将其解压 ...
- Android - Ant自动编译打包android项目 -- 1(转)
1. 背景: Eclipse用起来虽然方便,但是编译打包android项目还是比较慢,尤其当要将应用打包发布到各个渠道时,用Eclipse手动打包各种渠道包就有点不切实际了,这时候我们用到Ant帮我 ...
- 根据wsdl文件,Web工程自动生成webservice客户端调用
根据wsdl文件,Web工程自动生成webservice客户端调用 1,工具:带有webservice插件的eclips 2,步骤: (1),新建一个Web工程:WSDLTest (2),浏览器访问W ...
- eclipse新建web项目,发布 run as 方式和 new server然后添加项目方式。 后者无法自动编译java 成class文件到classes包下。
eclipse新建web项目,发布 run as 方式和 new server然后添加项目方式. 后者无法自动编译java 成class文件到classes包下. 建议使用run as - run ...
- Android-Ant自动编译打包android项目 -- 2 ----签名与渠道包
上篇介绍了怎么使用ant自动编译打包现有的android项目,这篇将继续介绍如果如何在ant打包应用的时候加入签名信息以及自动打包渠道包. 1. 加入签名信息: 在项目的根目录下建一个ant.prop ...
- ant:如何用ant将web project打包成war包
说明:src中的文件将不会呈现出来,诸位可以自己写一个简单的web项目,然后依照我所提供的ant脚本配置来设置. 文件结构如图所示: 配置为下: build.xml < ...
随机推荐
- 对于大于8046 bytes的行,RCSI/SI事务隔离级别无效
自SQL Server 2005起,我们有了READ COMMITTED SNAPSHOT ISOLATION level (RCSI) 和SNAPSHOT ISOLATION level (SI)两 ...
- css知识
margin和padding是什么意思 margin外边距,padding内边距,外边距表示一个元素的边到相邻元素的距离,内边距表示元素之间的内容和元素边框的距离. font:12px/1.5 表示什 ...
- LRU Cache
LRU Cache 题目链接:https://oj.leetcode.com/problems/lru-cache/ Design and implement a data structure for ...
- 重构第21天 合并继承 (Collapse Hierarchy)
理解:本文中的”合并继承”是指如果子类的属性和方法也适合于基类,那么就可以移除子类,从而减少依赖关系. 详解:上一篇我们讲到“提取子类”重构是指当基类中的一个责任不被所有的子类所需要时,将这些责任提取 ...
- 【C#】线程之Parallel
在一些常见的编程情形中,使用任务也许能提升性能.为了简化变成,静态类System.Threading.Tasks.Parallel封装了这些常见的情形,它内部使用Task对象. Parallel.Fo ...
- csharp: json to csharp
http://json2csharp.com/ http://jsonclassgenerator.codeplex.com/ http://jsonutils.com/ JSON生成类文件 http ...
- java设计模式--工厂模式
所谓工厂,就是要造产品,比如一个小型砖瓦厂,只有一个窑,既能造砖又能造瓦,这种叫简单工厂模式.规模稍大一点呢,我多个窑,有的窑专门造砖,有的窑专门造瓦,想造别的,比如瓷砖,我再用个专门的窑,这种 ...
- FL2440驱动添加(5)ADC驱动学习笔记
由图可知,模拟ADC分为两部分功能,一部分是触屏功能,另一部分就是普通ADC功能.分别可以产生INT_TC和INT_ADC 两个中断.该ADC模块总共有8个通道可以进行模拟信号的输入,分别是AIN0. ...
- php中的字符串常用函数(四) ord() 获得字符的ascii码 chr()获取ascii码对应的字符
ord('a');//=>97 返回小写a 的ascii码值97 chr(97);//=>a 返回ascii码表上的97对应的 小写a
- 机器学习实战 - 读书笔记(13) - 利用PCA来简化数据
前言 最近在看Peter Harrington写的"机器学习实战",这是我的学习心得,这次是第13章 - 利用PCA来简化数据. 这里介绍,机器学习中的降维技术,可简化样品数据. ...