You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ANT新手求助:解压Neo.jar时合并指定文件而非覆盖

Solution for ANT Unzip + Concat Target File Instead of Overwriting

Hey there! Let's work through this ANT challenge together. The goal is to unzip all files from Neo.jar normally, but only append the src/services/targetFile to the existing file in your destination directory instead of overwriting it. Here's a step-by-step approach:

Step 1: Unzip all files except the target file

First, extract every file from the jar excluding the specific src/services/targetFile. This way, all other files are handled normally, and we leave the existing target file untouched for later merging.

<!-- Unzip all files except src/services/targetFile -->
<unzip src="${output.dir}/Scala2.11/Neo.jar" dest="${standalone.jar.expanded.jars.dir}">
    <patternset>
        <exclude name="src/services/targetFile"/>
    </patternset>
</unzip>

Step 2: Extract the target file to a temporary directory

Next, pull just the src/services/targetFile from the jar into a temporary location. This lets us access its content without interfering with the existing file in your destination.

<!-- Create a temp directory if it doesn't exist -->
<mkdir dir="${temp.dir}"/>

<!-- Extract only the target file to temp -->
<unzip src="${output.dir}/Scala2.11/Neo.jar" dest="${temp.dir}">
    <patternset>
        <include name="src/services/targetFile"/>
    </patternset>
</unzip>

Note: Make sure to define ${temp.dir} in your build.xml (e.g., <property name="temp.dir" value="${basedir}/temp"/>).

Step 3: Append the temp target file to the existing one

Use ANT's concat task to merge the content of the temp file into the existing target file. The append="true" attribute ensures new content is added to the end—if the target file doesn't exist yet, it will be created automatically.

<!-- Append the temp target file to the existing one in destination -->
<concat destfile="${standalone.jar.expanded.jars.dir}/src/services/targetFile" append="true">
    <fileset dir="${temp.dir}" includes="src/services/targetFile"/>
</concat>

Step 4: Clean up the temporary directory

Finally, remove the temp directory to avoid leftover files cluttering your project.

<!-- Delete the temp directory -->
<delete dir="${temp.dir}"/>

This workflow ensures all files are unzipped as expected, with only the specified targetFile being appended instead of overwritten. It's flexible and works whether the target file already exists in the destination or not.

内容的提问来源于stack exchange,提问作者Trock Fuller

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:11:15