2

I am using maven-antrun-plugin to unpack a jar file into a folder. This jar file is generated in every build and has a variant TIMESTAMP (as seen in the following snippet). How can I unpack the jar file into folder that has the same name as the jar file? E.g. Folder should be /sample_TIMESTAMP and not /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>
Georgios Stathis
  • 533
  • 1
  • 6
  • 21
  • How is this JAR generated? Is it an artifact produced by the build? What are its Maven coordinates? Because a good way would be _not_ to use the `maven-antrun-plugin` but the `maven-dependency-plugin:unpack` goal. – Tunaki Feb 24 '16 at 16:00
  • I have tried already with the `maven-dependency-plugin:unpack` but the issue is that I would like to unpack the specific jar and not the one fetched from an M2 repo. – Georgios Stathis Feb 24 '16 at 16:05
  • Yes but where is this specific jar coming from? How is it built? Is it build from your project, meaning it is a additional artifact? With a classifier perhaps? – Tunaki Feb 24 '16 at 16:08
  • It comes from a P2 repository. It is being fetched by using another plugin: `tycho-p2-extras-plugin`. – Georgios Stathis Feb 24 '16 at 16:28

1 Answers1

3

To unzip into a new directory, first create the directory with <mkdir> and then change the dest of <unzip> to sample_TIMESTAMP:

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

You can use <pathconvert> to create a property with the name of the JAR file:

<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>

If the my-jar-file <fileset> could match multiple JAR files, use <restrict> to limit the matching to a single file.

Chad Nouis
  • 6,861
  • 1
  • 27
  • 28