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

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

问题描述

我不想依靠外部环境变量来强制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在这里给出了正确的答案:http://stackoverflow.com/a/10367745/962872

@Joop Eggen gave the right answer here: http://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>

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

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