【问题标题】:how to avoid UTF-8 encoding for binary with maven-resources-plugin?如何避免使用 maven-resources-plugin 对二进制进行 UTF-8 编码?
【发布时间】:2011-08-13 23:44:07
【问题描述】:

我正在使用 maven-resources-plugin 从我的项目中复制一些资源,但我的资源之一是二进制文件。输出显示它是 Using 'UTF-8' encoding to copy filtered resources 我的问题!!!

这是我的插件配置。

        <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>

我可以跳过二进制文件的 UTF-8 转换吗?

谢谢。

【问题讨论】:

  • Maven 不转换任何字符编码。它只需要知道在过滤期间必须应用 char 编码。二进制文件必须随时排除。

标签: maven-2 utf-8 maven maven-plugin maven-3


【解决方案1】:

设置两个单独的&lt;resource&gt; 元素,一个带有&lt;filtering&gt;false&lt;/filtering&gt;,另一个带有&lt;filtering&gt;true&lt;/filtering&gt;。使用&lt;resource&gt;&lt;includes&gt;&lt;excludes&gt; 元素通过扩展名从其中之一中排除您的二进制文件。

但是,资源插件在排除例如默认图片,所以请确保您使用的是最新版本。

【讨论】:

  • 好吧,我想复制文件!但未转换为 UTF-8。
【解决方案2】:

为了解决我的问题,我将此添加到我的配置中 maven binary filtering:

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

【讨论】:

    【解决方案3】:

    我遇到过类似的情况,二进制文件(以及 txt 和二进制数据的混合)被插件无意中处理,使其最终无法使用。

    为了解决这个问题,我只需要更明确地过滤哪些类型的文件,并保持所有其他文件不变,见下文:

    <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】:

      对于没有扩展名的已编译二进制文件(它在 RHEL 构建服务器上启动以进行某些组件测试),为它打算在其下运行的 Linux 版本添加了文件扩展名,并使用上面的 code-gijoe 的答案来确保maven 没有“过滤”它:

      <nonFilteredFileExtensions>                            
          <nonFilteredFileExtension>rhel</nonFilteredFileExtension>
      </nonFilteredFileExtensions>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-11-15
        • 2015-10-26
        • 1970-01-01
        • 2013-08-09
        • 2018-06-23
        • 1970-01-01
        • 2015-03-23
        • 2016-04-06
        相关资源
        最近更新 更多