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的更多相关文章

  1. Ant自动编译打包&发布 android项目

    Eclipse用起来虽然方便,但是编译打包android项目还是比较慢,尤其将应用打包发布到各个渠道时,用Eclipse手动打包各种渠道包就有点不切实际了,这时候我们用到Ant帮我们自动编译打包了. ...

  2. Andorid进阶7—— Ant自动编译打包&发布 android项目

    http://www.cnblogs.com/tt_mc/p/3891546.html Eclipse用起来虽然方便,但是编译打包android项目还是比较慢,尤其将应用打包发布到各个渠道时,用Ecl ...

  3. Ant自动编译打包android项目(转载)

      1.1   Ant安装 ant的安装比较简单,下载ant压缩包  http://ant.apache.org  (最新的为1.9.3版本),下载之后将其解压到某个目录(本人解压到E:\Progra ...

  4. (转载)Ant自动编译打包android项目

    1  Ant自动编译打包android项目 1.1   Ant安装 ant的安装比较简单,下载ant压缩包  http://ant.apache.org  (最新的为1.9.3版本),下载之后将其解压 ...

  5. Android - Ant自动编译打包android项目 -- 1(转)

    1.  背景: Eclipse用起来虽然方便,但是编译打包android项目还是比较慢,尤其当要将应用打包发布到各个渠道时,用Eclipse手动打包各种渠道包就有点不切实际了,这时候我们用到Ant帮我 ...

  6. 根据wsdl文件,Web工程自动生成webservice客户端调用

    根据wsdl文件,Web工程自动生成webservice客户端调用 1,工具:带有webservice插件的eclips 2,步骤: (1),新建一个Web工程:WSDLTest (2),浏览器访问W ...

  7. eclipse新建web项目,发布 run as 方式和 new server然后添加项目方式。 后者无法自动编译java 成class文件到classes包下。

    eclipse新建web项目,发布 run as 方式和 new server然后添加项目方式. 后者无法自动编译java 成class文件到classes包下. 建议使用run as  -  run ...

  8. Android-Ant自动编译打包android项目 -- 2 ----签名与渠道包

    上篇介绍了怎么使用ant自动编译打包现有的android项目,这篇将继续介绍如果如何在ant打包应用的时候加入签名信息以及自动打包渠道包. 1. 加入签名信息: 在项目的根目录下建一个ant.prop ...

  9. ant:如何用ant将web project打包成war包

    说明:src中的文件将不会呈现出来,诸位可以自己写一个简单的web项目,然后依照我所提供的ant脚本配置来设置. 文件结构如图所示:               配置为下: build.xml < ...

随机推荐

  1. [前端]分享一个Bootstrap可视化布局的网站

    如果你像我一样:是个前端渣,能看懂css和html,略懂Bootstarp,懒! 当你每次都想独立完成一个web页面而不知道从哪里下手的时候,那么下面的这个网站,就是你所以需要的! http://ww ...

  2. 手把手教你从购买vps到搭建一个node服务器

    要准备什么? 1.5刀 2.最好有FQ软件(可以用蓝灯) let's Go! 一.vps购买 vps可以选择digital ocean(do) 链接 ,由于是外国网站,响应比较慢,所以最好翻个墙. g ...

  3. 微软必应词典客户端的案例分析——个人Week3作业

    第一部分 调研,评测 Bug探索 Bug No1.高亮语义匹配错位 环境: windows8,使用必应词典版本PC版:3.5.0 重现步骤: 1. 搜索"funny face"这一 ...

  4. 第二sprint总结

    总结:在第二轮sprint中,团队的开发工作出现了极大的懈怠,团队成员分配的工作完成情况较差,进度较慢,希望能在最后一周中,完成预定的功能模块 个人贡献分: 124陈彦生:22=20*5*22% 14 ...

  5. 爆搜 + 模拟 --- codeforces 475C

    Problem's Link:http://codeforces.com/problemset/problem/475/Chttp://codeforces.com/problemset/proble ...

  6. GitHub Extension for Visual Studio 2.0 is now available

    GitHub Extension for Visual Studio 2.0 is now available We're pleased to announce that version 2.0 o ...

  7. Use the PDFs below or the HTML contents to the left to install and configure P6 EPPM and its additional components.

    Welcome to Your Documentation   Use the PDFs below or the HTML contents to the left to install and c ...

  8. 微软参考源代码 referencesource.microsoft.com

    微软参考源代码 http://referencesource.microsoft.com/ referencesource 下载地址 https://github.com/Microsoft/refe ...

  9. Silverlight开源项目与第三方控件收集

    http://easysl.codeplex.com/ http://compositewpf.codeplex.com/ http://silverlight.codeplex.com/releas ...

  10. c#对Aspose.Word替换书签内容的简单封装

    辅助类1  json和datatable互转:   using System; using System.Collections.Generic; using System.Linq; using S ...