Total Pageviews

Friday, April 06, 2007

Resource filtering in Maven2 corrupts images in Jar archive

I had a very strange problem with the Maven2 resource filtering behaviour. I have a resource directory containing XML files and PNG images. Everytime I started to build a JAR archive of my project the images in there were corrupted.
It took me some time to identify the resource filtering as the source of the problem. My configuration filtered all files in that directory. So the images were filtered as well. If the resource plugin sees a filter token in a binary file which in configured to be filtered it replaces the token with the value.
So the solution is either to move the images to a different resource folder or use inclusions/exclusions on the filtered resource directory.
If you plan to just have a single resource directory your configuration of the resource filtering may look like this:




true
${basedir}/src/main/resources

**/*.jpg
**/*.gif
**/*.png



${basedir}/src/main/resources
false

**/*.jpg
**/*.gif
**/*.png




I found the solution in the user mailing list. The interesting posts are:
http://www.nabble.com/forum/ViewPost.jtp?post=4231228&framed=y&skin=177
and this one:
http://www.nabble.com/forum/ViewPost.jtp?post=4231635&framed=y&skin=177

No comments:

Post a Comment