I\'m using the maven-resources-plugin to copy some resources from my project but one of my resources is a binary file. The output says it is Using \'UTF-8\' encoding t
Well to solve my problem I added this to my configuration maven binary filtering:
<nonFilteredFileExtensions>
<nonFilteredFileExtension>dcm</nonFilteredFileExtension>
</nonFilteredFileExtensions>
Set up two separate <resource>
elements, one with <filtering>false</filtering>
and the other with <filtering>true</filtering>
. Use the <includes>
and <excludes>
elements of <resource>
to exclude your binary files by extension from one of them.
The resources plugin is however getting smarter about excluding e.g. images by default, so make sure you use the latest version.
I came across similar situation where a binary file (well a mix of txt and binary data) was inadvertently processed by the plugin, making it unusable at the end.
To solve this, I just had to make filtering a bit more explicit as to which types of file to filter and keeping all others, untouched, see below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>filter-config-files</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration><outputDirectory>${project.build.directory}/config-filtered</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/nar/${project.name}-${project.version}-noarch</directory>
<!-- enabling filetering ONLY on these file types -->
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.sh</include>
</includes>
</resource>
<resource>
<directory>${project.build.directory}/nar/${project.name}-${project.version}-noarch</directory>
<!-- now excluding filtering on ALL OTHER file types but still including them in the archive -->
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
For a compiled binary that had no extension (it gets launched on the RHEL build server for some component tests), added a file extension for the Linux version it was intended to run under and used code-gijoe's answer above to ensure that maven did not "filter" it:
<nonFilteredFileExtensions>
<nonFilteredFileExtension>rhel</nonFilteredFileExtension>
</nonFilteredFileExtensions>