how to avoid UTF-8 encoding for binary with maven-resources-plugin?

坚强是说给别人听的谎言 提交于 2019-11-29 06:15:16

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!