更新现有WAR文件中的文件

Nir*_*tel 15 ant

我正在尝试使用ANT WAR任务更新现有WAR文件中的文件.我需要用我的硬盘中的新文件替换WAR中文件夹中的一组xml文件.

<war destfile="myApp.war" update="true" >
    <zipfileset dir="<PathToStubsFolderOnHDD>" includes="**/*.xml" prefix="<PathToStubsFolderInWAR>"/>
</war>
Run Code Online (Sandbox Code Playgroud)

如果原始WAR没有具有相同名称的xmls,则此方法可以正常工作.但是,如果原始WAR包含具有相同名称的xmls; WAR任务不会使用HDD中的文件更新它们.

ANT WAR任务文档如下:

更新| 指示是否更新或覆盖目标文件(如果已存在).默认为"false".
重复| 找到重复文件时的行为.有效值为"add","preserve"和"fail".默认值为"add".

如果我使用update ="false"; 原始WAR中的所有其他文件都将被删除,并且只存储新的xmls.

使用duplicate ="add"也没有任何效果.

关于如何实现这一点的任何建议?

Ait*_*ito 11

似乎使用update=true选项,war文件比您要更新的文件更新.有人建议touch使用"0" 应用任务来解决问题.

zip任务仅检查您要添加到现有zip的源文件是否比zip更新.<touch millis="0" />在添加之前,解决方法将是zip文件.

或者你可以做相反的事情:

在XML文件上执行任务touch之前war使其工作.


Nir*_*tel 9

谢谢Aito!

这是完整的ANT脚本:

<target name = "UpdateWARWithStubs"
    description="Updates WAR file with files from Stub folder">

    <!-- Use touch to set modification time of all stubs to current time. This will force war task to update stub files inside the war -->
    <tstamp> <format property="touch.time" pattern="MM/dd/yyyy hh:mm aa"/>  </tstamp>
    <touch datetime="${touch.time}">
        <fileset dir="${path.to.stubs.on.hdd}" />
    </touch>

    <war destfile="myApp.war" update="true">
        <zipfileset dir="${path.to.stubs.on.hdd}"  prefix="${path.to.stubs.in.war}"/>
    </war>
</target>
Run Code Online (Sandbox Code Playgroud)