以下是我的另一種方法POC,以防有人感興趣。如果我們找不到「嵌套」更新,我會使用它。
<property name="ear.file1" value="file1.ear"/>
<property name="war.file1" value="war1.war"/>
<property name="war.file" value="war.war"/>
<property name="war.file.backup" value="warBk.war"/>
<property name="text.file1" value="1.txt"/>
<property name="text.file2" value="2.txt"/>
<property name="xml.application1" value="application.xml"/>
<target name="clean">
<delete file="${ear.file1}"/>
<delete file="${war.file}"/>
<delete file="${war.file.backup}"/>
</target>
<target name="run">
<!-- Our war file contains 1.txt, allows us add 2.txt and verify updates properly -->
<copy file="${war.file1}" tofile="${war.file}"/>
<!-- simple ear that will be updated -->
<ear earfile="${ear.file1}" appxml="${xml.application1}">
<fileset dir="." includes="${text.file1}"/>
<fileset dir="." includes="${war.file}"/>
</ear>
<!-- Backup war, for comparision purposes -->
<move file="${war.file}" tofile="${war.file.backup}" overwrite="true" />
<!-- Extact the war we just added -->
<unzip dest="." src="${ear.file1}" overwrite="true" >
<patternset>
<include name="${war.file}" />
</patternset>
</unzip>
<!-- Update the war by adding a file -->
<war destfile="${war.file}" update="true">
<fileset dir="." includes="${text.file2}"/>
</war>
<!-- Update the ear with our updated war -->
<ear earfile="${ear.file1}" appxml="${xml.application1}" update="true">
<fileset dir="." includes="${war.file}"/>
</ear>
</target>
<target name="main" depends="clean,run"/>