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

痴心易碎 提交于 2019-11-27 23:44:35

问题


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 to copy filtered resources which I my problem!!!

Here is my plugin configuration.

        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.5</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <!-- here the phase you need -->
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/autopublisher</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/autopublisher</directory>
                                <filtering>true</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Can I skip the UTF-8 conversion for binaries?

Thank you.


回答1:


Well to solve my problem I added this to my configuration maven binary filtering:

<nonFilteredFileExtensions>                            
    <nonFilteredFileExtension>dcm</nonFilteredFileExtension>
</nonFilteredFileExtensions>



回答2:


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.




回答3:


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>



回答4:


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>


来源:https://stackoverflow.com/questions/5806792/how-to-avoid-utf-8-encoding-for-binary-with-maven-resources-plugin

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