Ant打包war文件

J2EE发布web项目打包war 文件。 压缩JS,CSS文件。

把deploy文件夹复制到项目根目录。运行ant脚本,即可打包war文件。

deploy文件下载地址:http://download.csdn.net/detail/w123456h19/5624633


<?xml version="1.0" encoding="UTF-8"?>

<project basedir="." default="buildSanFull" name="项目War包发布">
<property name="build.number" value="1.0.0" />
<!-- 源码地址 -->
<property name="src.dir" value="src"/>
<!-- 应用名称--> 
<property name="appname" value="SanFullVisit" />
<!-- 目标目录 , 如deploy-->
<property name="deploy.dir" value="${basedir}/deploy" /> 
<!-- 源目录 -->
<property name="web.dir" value="${basedir}/WebRoot"/>
<!-- 编译后代码地址 -->
<property name="class.dir" value="${deploy.dir}/output/WebRoot/WEB-INF/classes"/>
<!-- web下jar目录 -->
<property name="project.web.lib" value="WebRoot/WEB-INF/lib"/>
<!-- CSS,JS压缩支持库 -->
    <property name="compress.lib" value="${deploy.dir}/lib/yuicompressor-2.4.2.jar" />

<!-- 清空发布前环境 -->
<target name="clean">
<!-- 删除以前编译的war包 -->
<delete verbose="true" file="${deploy.dir}/${appname}.war"/>
<!-- 删除准备打包的代码目录 -->
<delete includeEmptyDirs="true" dir="${deploy.dir}/output/WebRoot"/>
<!-- 删除准备编译后的代码目录 -->  
<delete dir="${class.dir}"/>  
<!-- 创建准备编译后的代码目录 -->
<mkdir dir="${class.dir}"/>
<echo message="环境清理结束"/>
</target>


<!-- jar地址 -->
<path id="classpath">
 <fileset dir="${project.web.lib}">
  <include name="*.jar"/>
 </fileset>
</path>

<!-- 编译项目-->
<target name="compile" depends="clean">
   <javac destdir="${class.dir}" encoding="UTF8" optimize="true" debug="on">                    
       <src path="${src.dir}" />      
       <classpath refid="classpath"/>  
   </javac>  
<!--拷贝配置文件等-->
<copy todir="${web.dir}/WEB-INF/classes" overwrite="true">
       <fileset dir="${src.dir}">
           <include name="**/*.xml"/>
        <include name="**/*.properties"/>
       </fileset>
</copy>
</target>

<!-- 准备项目文件到output目录 -->
<target name="output" depends="compile">
<copy todir="${deploy.dir}/output/WebRoot" overwrite="true">
       <fileset dir="${web.dir}">
<include name="**/*.html"/>
        <include name="**/*.htm"/>
<include name="**/*.jsp"/>
        <include name="**/*.css"/>
<include name="**/*.js"/>
        <include name="**/*.xml"/>
        <include name="**/*.jpg"/>
        <include name="**/*.png"/>
        <include name="**/*.gif"/>
        <include name="**/*.MF"/>
        <include name="**/*.jar"/>
       </fileset>
</copy>
<copy todir="${deploy.dir}/output/WebRoot/Web-INF/classes">
<fileset dir="${src.dir}">
        <include name="**/*.properties"/>
        <include name="**/*.sql"/>
        <include name="**/*.wsdl"/>
        <include name="**/*.wsdd"/>
</fileset>
</copy>
<!-- 创建手机更新包存放目录 -->
<mkdir dir="${deploy.dir}/output/WebRoot/update"/>

<!-- ============================================= --> 
   <!-- 压缩CSS,JS -->
   <!-- ============================================= -->
<echo message="yuicompressor开始CSS压缩"/>
<apply executable="java" parallel="false" failοnerrοr="true" dest="${deploy.dir}/output/WebRoot" append="false" force="true">
<fileset dir="${deploy.dir}/output/WebRoot" includes="**/*.css" />
<arg line="-jar" />
<arg path="${compress.lib}" />
<arg line="--charset utf-8" /> 
<srcfile />
<arg line="-o" />
<mapper type="glob" from="*.css" to="*.css" />
<targetfile />
   </apply>
<echo message="yuicompressor开始JS压缩"/>
<apply executable="java" parallel="false" failοnerrοr="true" dest="${deploy.dir}/output/WebRoot" append="false" force="true">
<fileset dir="${deploy.dir}/output/WebRoot" includes="**/*.js" />
<arg line="-jar" />
<arg path="${compress.lib}" />
<arg line="--charset utf-8" /> 
<srcfile />
<arg line="-o" />
<mapper type="glob" from="*.js" to="*.js" />
<targetfile />
   </apply>
<echo message="yuicompressor压缩完成"/>
    </target>

<!-- ============================================= --> 
<!-- build .war file -->
<!-- ============================================= -->
<target name="buildSanFull" depends="output">
<war destfile="${deploy.dir}/output/${appname}.war" webxml="${deploy.dir}/output/WebRoot/WEB-INF/web.xml" defaultexcludes="true" >
<fileset dir="${deploy.dir}/output/WebRoot">
<exclude name="**/*.log" />
<exclude name="**/work/**" />
<exclude name="**/tmp/**" />
</fileset>
</war>
<delete includeEmptyDirs="true" dir="${deploy.dir}/output/WebRoot"/>
</target>
</project>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值