I’m currently working on a project which requires the build to produce a zip archive of the jar and some other stuff (doc files mainly). I’ve used the maven assembly plugin, with an assembly descriptor to help me out here. However, there was one slightly unusual requirement – I needed to change the name of the jar so that inside the zip, it has a non-standard name, and no version number (the reasons behind this are fairly weak, but basically it’s because a load of other scripts, which we can’t change, expect to find the jar in this non-standard format).
So, the build produces:
myproject-1.0.0.0-SNAPSHOT.jar
but in the zip I need to have:
my-project.jar
Here’s how I did it.
- Include the maven-assembly plugin in the build:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-1</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/kit.xml</descriptor>
</descriptors>
<finalName>${pom.artifactId}-${pom.version}</finalName>
<outputDirectory>build/maven/${pom.artifactId}/target</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
- Create the kit.xml in src/main/assembly and specify <destName> in the file inclusion. Here’s my kit.xml:
<assembly>
<id>kit</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<outputDirectory>doc</outputDirectory>
<includes>
<include>*.*</include>
</includes>
</fileSet>
</fileSets>
<files>
<file>
<source>build/maven/${artifactId}/target/${artifactId}-${version}.${packaging}</source>
<outputDirectory>/</outputDirectory>
<destName>my-project.jar</destName>
</file>
</files>
</assembly>
As you can see, the assembly descriptor has a “files” section, which is what does the trick for us. I’ve isolated the actual section below for clarity:
<files>
<file>
<source>build/maven/${artifactId}/target/${artifactId}-${version}.${packaging}</source>
<outputDirectory>/</outputDirectory>
<destName>my-project.jar</destName>
</file>
</files>
Very useful link, but i’ve tried something similar and it creates two files, myfile.war, with all the default options, and myfile-permissions.war, with renamed files (that takes from the first one) and so on.
“permissions” as “kit” in your example, is stored in kit and is appended to our project name for the secondary .war or .zip. I cannot leave it empty…do you know a way for renaming files inside the “primary” war or zip that is created?
Thanks
Dámaris.
I have to say that this information is awesome. I am extremely awed to uncover such useful guides on adjustable piano bench.
Thank you — saved my bacon
Wow, that’s what I was looking for, what a stuff! existing here at this blog, thanks admin of this web page.
Hi would you mind sharing which blog platform you’re working with? I’m looking to
start my own blog soon but I’m having a tough time selecting between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I’m looking for something unique.
P.S Sorry for being off-topic but I had to ask!
Here is my solution via outputFileNameMapping using dependency sets with war files
${project.groupId}:*:war:${project.version}
true
/resources/webapps
false
${artifact.artifactId}.${artifact.extension}
Thanks Gede great input. I think that those things are imarptont (live reloading of settings etc) but should not be designed in from the outset (but then I’m an emergent design guy). Frameworks like OSGi are compelling, but charge a very high complexity tax. Allowing for fast (and automated) rolling restarts including re-deployment of externalised settings is most imarptont and as you say this requires redundancy and a simple architecture.
Awesome..thanks
Thank you ! Thats exactly what I am searching fory!
thank you.
custom-name
false
http://stackoverflow.com/a/3269902/386713
Thank for this solution, have you an idea on how modify files contents using maven assembly plugin?
Regards.