1

我正在使用 maven-antrun-plugin 将 jar 文件解压缩到文件夹中。这个 jar 文件在每个构建中生成,并且有一个变体 TIMESTAMP(如下面的代码片段所示)。如何将 jar 文件解压缩到与 jar 文件同名的文件夹中?例如,文件夹应该是 /sample_TIMESTAMP 而不是 /folder

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>unpack-jar-features</id>
            <phase>install</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <target>
                    <echo message="unpack jar file" />
                    <unzip dest="/folder">
                        <fileset dir="/folder">
                            <include name="sample_TIMESTAMP.jar" />
                        </fileset>
                    </unzip>
                </target>
            </configuration>
        </execution>
    </executions>
</plugin>
4

1 回答 1

2

要解压缩到新目录,首先创建目录,<mkdir>然后将destof更改<unzip>sample_TIMESTAMP

<mkdir dir="/sample_TIMESTAMP"/>
<unzip dest="/sample_TIMESTAMP">
    <fileset dir="/folder">
        <include name="sample_TIMESTAMP.jar" />
    </fileset>
</unzip>

您可以使用<pathconvert>JAR 文件的名称创建属性:

<fileset id="my-jar-file" dir="/folder">
    <include name="sample_*.jar"/>
</fileset>
<pathconvert property="my-jar-file-name">
    <chainedmapper>
        <flattenmapper/>
        <globmapper from="*.jar" to="*"/>
    </chainedmapper>
    <path>
        <fileset refid="my-jar-file"/>
    </path>
</pathconvert>
<mkdir dir="/${my-jar-file-name}"/>
<unzip dest="/${my-jar-file-name}">
    <fileset refid="my-jar-file"/>
</unzip>

如果my-jar-file <fileset>可以匹配多个 JAR 文件,请使用<restrict>将匹配限制为单个文件。

于 2016-02-24T15:30:04.217 回答