即使已配置,Maven安装也不以UTF-8编码 [英] Maven install does not encode in UTF-8 even if configured
问题描述
我的项目编码有问题.
Hi I have a problem with the encoding of my project.
当我从Eclipse运行JUnit测试时,没有失败.问题是当我执行maven> clean maven> install时,其中一项测试失败.
When I run JUnit tests from eclipse, there are no failures. The problem is when I do maven > clean maven > install, one of the tests fails.
我有这个字符串:ADMINISTRACIÓN",当我从Eclipse运行JUnit时很好,但是我已经打印了变量,并且当maven进行测试时,该字符串的值是:"ADMINISTRACI.N".
I have this string: "ADMINISTRACIÓN", and it's fine when i run the JUnit from eclipse, but I've printed the variable and when maven does the tests, the value of this string is: "ADMINISTRACI�N".
我已经将在eclipse中可以找到的编码的每个属性更改为UTF-8. -通过以下方式配置pom:
I've changed every property I could find of encoding in eclipse to UTF-8. -Configured the pom this way:
(...)
<project>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
(...)
</properties>
</project>
(...)
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
(...)
但是输出是相同的.我有一个与我的项目相同的项目,并且具有相同的eclipse客户端和配置,并且她的maven测试可以轻松打印口音.
But the output is the same. I have a coworker that has the same project than me, and the same eclipse client and config, and her maven tests print accents with no trouble.
还有其他想法吗?
非常感谢!
推荐答案
尝试通过以下方式运行您的构建:
Try run your build with:
mvn -DargLine=-Dfile.encoding=UTF-8 clean insall
如果有帮助,您可以在项目中配置surefire:
if help, you can configure surefire in project:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
</configuration>
</plugin>
可能会出现问题,因为System.out
使用默认系统编码,您可以通过设置file.encoding
java属性来更改此设置.
Problem may occur because System.out
use default system encoding, you can change this be setting file.encoding
java property.
这篇关于即使已配置,Maven安装也不以UTF-8编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!