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 的情况下
基础教程推荐
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java Swing计时器未清除 2022-01-01
