如何使用 maven-resources-plugin 避免二进制文件的 UTF-8 编码?

发布于 2024-11-03 09:08:06 字数 1330 浏览 1 评论 0原文

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

这是我的插件配置。

        <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 转换吗?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

染柒℉ 2024-11-10 09:08:06

为了解决我的问题,我将其添加到我的配置中 maven 二进制过滤 :

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

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

<nonFilteredFileExtensions>                            
    <nonFilteredFileExtension>dcm</nonFilteredFileExtension>
</nonFilteredFileExtensions>
风启觞 2024-11-10 09:08:06

设置两个单独的 元素,一个使用 false,另一个使用 true;。使用 元素通过扩展名从其中之一排除二进制文件。

然而,资源插件在默认情况下排除图像等方面变得越来越智能,因此请确保使用最新版本。

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.

憧憬巴黎街头的黎明 2024-11-10 09:08:06

我遇到过类似的情况,插件无意中处理了二进制文件(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>

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>
时间海 2024-11-10 09:08:06

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

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文