ANT打war包时出现重复文件的解决方法

最近用ant给java web程序打war包时发现打出来的war包里面WEB-INF里的文件均有两个,后来发现加上一句fileset,include,exclude语句之后就没有重复文件了

打包代码如下

<target name="antwar" depends="build" description="not wrap the java file to .war">
<wbr><wbr>&lt;delete dir="${build.src}" /&gt;<br><wbr><wbr>&lt;war warfile="${war.dest}/anttest.war" webxml="${buildwar.dest}/WEB-INF/web.xml"&gt;<br><wbr><wbr><wbr>&lt;lib dir="${buildwar.dest}/WEB-INF/lib" /&gt;<br><wbr><wbr><wbr>&lt;classes dir="${build.dest}" /&gt;<br><wbr><wbr><wbr><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">&lt;fileset dir="${buildwar.dest}"&gt;<br><wbr><wbr><wbr><wbr>&lt;include name="***.*" /&gt;<br><wbr><wbr><wbr>&lt;/fileset&gt;<br></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><wbr><wbr>&lt;/war&gt;<br><wbr>&lt;/target&gt;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

如果要忽略一些文件就需要使用fileset和excludes
比如:复制一个目录中所有.java为结尾的文件,除去文件名含有Test字符的文件
<target name="copyfiles"><wbr><wbr><wbr><wbr><wbr><wbr><br><wbr><wbr><wbr><wbr><wbr><wbr>&lt;copy todir="${dest.dir}" overwrite="true"&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>&lt;fileset dir="${src.dir}"&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>&lt;include name="***Test*"/&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>&lt;/fileset&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr>&lt;/copy&gt;<br> &lt;/target&gt;<br><br> 复制一个目录中所有文件,除去含有Test字符的目录<br> &lt;target name="copyfiles"&gt;<wbr><wbr><wbr><wbr><wbr><wbr><br><wbr><wbr><wbr><wbr><wbr><wbr>&lt;copy todir="${dest.dir}" overwrite="true"&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>&lt;fileset dir="${src.dir}"&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>&lt;exclude name="****"/&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>&lt;/fileset&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr>&lt;/copy&gt;<br> &lt;/target&gt;<br> 需要加/**<br></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

下面附上build.xml的所有代码,用于打包java web程序,并将war包拷贝(发布)到tomcat的webapp路径下面

<?xml version="1.0" encoding="GB2312"?>
<project basedir="." default="publish" name="anttest">
<wbr>&lt;target name="init" description="set initiation directory"&gt;<br><wbr><wbr>&lt;property name="src" value="${basedir}/src" /&gt;<br><wbr><wbr>&lt;property name="config" value="${basedir}/config" /&gt;<br><wbr><wbr>&lt;property name="lib" value="${basedir}/WebContent/WEB-INF/lib" /&gt;<br><wbr><wbr>&lt;property name="webapp" value="${basedir}/WebContent" /&gt;<br><wbr><wbr>&lt;property name="packages" value="ant.*" /&gt;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr><wbr>&lt;property name="build.src" value="${basedir}/AntBuild/anttest/src" /&gt;<br><wbr><wbr>&lt;property name="build.dest" value="${basedir}/AntBuild/anttest/WEB-INF/classes" /&gt;</wbr></wbr></wbr></wbr>

<wbr><wbr>&lt;property name="buildwar.dest" value="${basedir}/AntBuild/anttest" /&gt;<br><wbr><wbr>&lt;property name="build.javadocs" value="${basedir}/Antbuild/doc" /&gt;<br><wbr><wbr>&lt;property name="jar.dest" value="${basedir}/AntBuild/jar" /&gt;<br><wbr><wbr>&lt;property name="war.dest" value="${basedir}/AntBuild/war" /&gt;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr><wbr>&lt;property name="tomcat.home" value="D:\JavaSoft\apache-tomcat-6.0.32" /&gt;<br><wbr><wbr>&lt;property name="j2eelib.dir" value="D:\JavaSoft\eclipse-gee-ganymede-win32\eclipse\plugins" /&gt;</wbr></wbr></wbr></wbr>

<wbr><wbr>&lt;path id="classpath"&gt;<br><wbr><wbr><wbr>&lt;fileset dir="${j2eelib.dir}"&gt;<br><wbr><wbr><wbr><wbr>&lt;include name="***.jar" /&gt;<br><wbr><wbr><wbr>&lt;/fileset&gt;<br><wbr><wbr>&lt;/path&gt;<br><wbr>&lt;/target&gt;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr>&lt;target name="prepare" depends="init" description="create directories for war, and copy source file to war direcoty"&gt;<br><wbr><wbr>&lt;mkdir dir="${build.src}" /&gt;<br><wbr><wbr>&lt;mkdir dir="${build.dest}" /&gt;<br><wbr><wbr>&lt;mkdir dir="${buildwar.dest}" /&gt;<br><wbr><wbr>&lt;mkdir dir="${jar.dest}" /&gt;<br><wbr><wbr>&lt;mkdir dir="${war.dest}" /&gt;<br><wbr><wbr>&lt;copy todir="${build.src}"&gt;<br><wbr><wbr><wbr>&lt;fileset dir="${src}" /&gt;<br><wbr><wbr>&lt;/copy&gt;<br><wbr><wbr>&lt;copy todir="${build.src}"&gt;<br><wbr><wbr><wbr>&lt;fileset dir="${config}" /&gt;<br><wbr><wbr>&lt;/copy&gt;<br><wbr><wbr>&lt;copy todir="${buildwar.dest}"&gt;<br><wbr><wbr><wbr>&lt;fileset dir="${webapp}" /&gt;<br><wbr><wbr>&lt;/copy&gt;<br><wbr>&lt;/target&gt;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr>&lt;target name="build" depends="prepare" description="compile the java file. copy configuration files about properties to compile result directory"&gt;<br><wbr><wbr>&lt;javac srcdir="${build.src}" destdir="${build.dest}"&gt;<br><wbr><wbr><wbr>&lt;classpath refid="classpath" /&gt;<br><wbr><wbr>&lt;/javac&gt;<br><wbr><wbr>&lt;copy todir="${build.dest}"&gt;<br><wbr><wbr><wbr>&lt;fileset dir="${build.src}"&gt;<br><wbr><wbr><wbr><wbr>&lt;include name="***.*" /&gt;<br><wbr><wbr><wbr><wbr>&lt;exclude name="WEB-INF*.*" /&gt;<br><wbr><wbr><wbr>&lt;/fileset&gt;<br><wbr><wbr>&lt;/war&gt;<br><wbr>&lt;/target&gt;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr>&lt;target name="publish" depends="antwar,clean" description="publish .war to tomcat directory"&gt;<br><wbr><wbr>&lt;copy todir="${tomcat.home}/webapps"&gt;<br><wbr><wbr><wbr>&lt;fileset dir="${war.dest}"&gt;<br><wbr><wbr><wbr><wbr>&lt;include name="***.classes" /&gt;<br><wbr><wbr>&lt;/delete&gt;<br><wbr><wbr>&lt;delete dir="${buildwar.dest}" /&gt;<br><wbr>&lt;/target&gt;<br> &lt;/project&gt;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值