有没有办法在不使用外部 JAVA_TOOL_OPTIONS 的情况下使用 UTF-8 使 Maven 构建类文件? [英] Is there a way to make maven build class files with UTF-8 without using the external JAVA_TOOL_OPTIONS?

查看:31
本文介绍了有没有办法在不使用外部 JAVA_TOOL_OPTIONS 的情况下使用 UTF-8 使 Maven 构建类文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想依赖外部环境变量来强制 maven 使用 UTF-8 构建我的类.在 Mac 上,我在使用 maven 构建时遇到了各种各样的问题.只有以下选项解决了问题:

I don't want to be dependable on a external environment variable to force maven to build my classes with UTF-8. On Mac, I was getting all sorts of problems when building with maven. Only the option below solved the problem:

export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
mvn clean install

但是,我正在分发我的项目,依靠用户设置此环境变量来正确构建项目是没有意义的.

However I am distributing my project and it does NOT make sense to rely on the user to set this environment variable to build the project correctly.

按照此处所述尝试所有内容:为 clojure 启用 UTF-8 编码源文件

Tried everything as described here: enabling UTF-8 encoding for clojure source files

有人对这个很棒的 Maven 问题有所了解吗?

Anyone has a light on that awesome Maven issue?

推荐答案

@Joop Eggen 在这里给出了正确答案:https://stackoverflow.com/a/10367745/962872

@Joop Eggen gave the right answer here: https://stackoverflow.com/a/10367745/962872

仅定义该属性是不够的.您必须在适当的插件中传递它.它不会在里面变魔术.

It is not enough to define that property. You MUST pass it inside the appropriate plugins. It won't go by magic inside there.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>...</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <encoding>${project.build.sourceEncoding}</encoding>
    </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>...</version>
    <configuration>
        <encoding>${project.build.sourceEncoding}</encoding>
    </configuration>
</plugin>
...
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

这篇关于有没有办法在不使用外部 JAVA_TOOL_OPTIONS 的情况下使用 UTF-8 使 Maven 构建类文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆