Is there a way to make maven build class files with UTF-8 without using the external JAVA_TOOL_OPTIONS?(有没有办法在不使用外部 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 构建类文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:有没有办法在不使用外部 JAVA_TOOL_OPTIONS 的情况下


基础教程推荐
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01