如何在 exec-maven-plugin 中设置 file.encoding 属性?

发布于 2024-12-29 02:20:04 字数 557 浏览 3 评论 0原文

我尝试通过 exec-maven-plugin 执行我的独立应用程序,但它以 WIN 编码开始,而不是 UTF-8。我读到了有关 Java 命令行键 -Dfile.encoding=UTF-8 的信息。如何将此属性设置到我的应用程序? 谢谢。

Maven pom:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <configuration>
                <executable>java</executable>
                <mainClass>my.main.Class</mainClass>
            </configuration>                
        </plugin>

I trying to exec my standalone application via exec-maven-plugin, but it started with WIN encoding, not UTF-8. I read about Java command line key -Dfile.encoding=UTF-8. How to set this property to my application?
Thanx.

maven pom:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <configuration>
                <executable>java</executable>
                <mainClass>my.main.Class</mainClass>
            </configuration>                
        </plugin>

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

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

发布评论

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

评论(3

2025-01-05 02:20:04

要设置 mvn exec:java 的编码,请设置 MAVEN_OPTS 环境变量,例如:

export MAVEN_OPTS=-Dfile.encoding=utf-8

以下是 exec-maven-plugin 用法 页面显示:

注意:java 目标不会生成新进程。您想要传递给执行类的任何特定于 VM 的选项都必须使用 MAVEN_OPTS 环境变量传递给 Maven VM。例如

MAVEN_OPTS=-Xmx1024m

否则请考虑使用 exec 目标。

To set encoding for mvn exec:java, set MAVEN_OPTS environment variable, e.g.:

export MAVEN_OPTS=-Dfile.encoding=utf-8

Here is what exec-maven-plugin usage page says:

Note: The java goal doesn't spawn a new process. Any VM specific option that you want to pass to the executed class must be passed to the Maven VM using the MAVEN_OPTS environment variable. E.g.

MAVEN_OPTS=-Xmx1024m

Otherwise consider using the exec goal.

没有伤那来痛 2025-01-05 02:20:04

根据 exec-maven-plugin 文档,它应该如下所示:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <configuration>
            <mainClass>my.main.Class</mainClass>
            <commandlineArgs>-Dfile.encoding=UTF-8</commandlineArgs>
        </configuration>                
    </plugin>

According to the exec-maven-plugin documentation, it should look like this:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <configuration>
            <mainClass>my.main.Class</mainClass>
            <commandlineArgs>-Dfile.encoding=UTF-8</commandlineArgs>
        </configuration>                
    </plugin>
苏璃陌 2025-01-05 02:20:04

比 Todd 的方法更直接(不过他的方法仍然很酷):

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <configuration>
        <mainClass>my.main.Class</mainClass>
        <systemProperties>
            <systemProperty>
                <key>file.encoding</key>
                <value>UTF-8</value>
            </systemProperty>
        </systemProperties>
    </configuration>                
</plugin>

示例此处

more direct method than Todd's (his one's still cool though):

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <configuration>
        <mainClass>my.main.Class</mainClass>
        <systemProperties>
            <systemProperty>
                <key>file.encoding</key>
                <value>UTF-8</value>
            </systemProperty>
        </systemProperties>
    </configuration>                
</plugin>

samples here.

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