I have a Java project that, when mvn install
is executed on it, generates a JAR file. So far so good.
After that generation, I'd like to rename the resultant JAR file to something with an arbitrary extension. For example, say the resultant JAR that is generated is called "Foo.jar", I'd like to rename it to "Foo.baz"
I'm trying to ascertain the magical plugin combo that will allow me to do this. So far, I've tried the following, based on this SO answer:
<project>
...
<build>
<finalName>Foo</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<copy file="${project.build.directory}/${project.build.finalName}.jar"
tofile="${project.build.directory}/${project.build.finalName}.baz" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-instrumented-jar</id>
<phase>verify</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/${project.build.finalName}.baz</file>
<type>baz</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
So, two things. First off, the above plugins don't seem to actually do anything. Also, I'm not clear on what the second plugin is trying to accomplish.
I've also attempted to do this in assembly separately from the above plugins, which didn't go so well. My assembly file (Note that I didn't include the plugin, because it's completely boilerplate):
<assembly xmlns="http://maven.apache.org/xsd/assembly"
xsi:schemaLocation="http://maven.apache.org/xsd/assembly-1.0.0.xsd">
<id>dist</id>
<formats>
<format>jar</format>
<format>dir</format>
</formats>
<files>
<file>
<source>${project.build.directory}/${project.build.finalName}.${packaging}</source>
<outputDirectory>${project.build.directory}</outputDirectory>
<destName>${project.build.finalName}.baz</destName>
</file>
</files>
</assembly>
Attempting to run this assembly, however, resulted in: Failed to create assembly: Error creating assembly archive dist: A zip file cannot include itself
So, at this point, I'm at a loss. After about an hour of Googling, I'm under the impression that the ant script is the way to go for this, but I couldn't begin to tell you why it isn't working.
Any help is appreciated.