如何在具有不同编码的异构环境中使用maven?

tan*_*ens 3 linux svn windows encoding maven-2

我在linux服务器(Debian)上创建了一个svn repositoy,并在windows机器上使用客户端检查我的java源代码.

现在我在不同的Linux服务器(Ubuntu)上设置了一个Hudson服务器,以定期对我的代码运行测试.但是测试因编译器错误而失败:

Error: unmappable character for encoding ASCII
Run Code Online (Sandbox Code Playgroud)

在我的Windows机器上,我使用了默认编码Cp1252.在我的svn服务器上,我可以对我的源进行本地检查,看起来很好.在我的Hudson服务器上,结帐包含非法字符.

我必须调整哪些参数,以便所有三个系统都使用工作编码?

编辑2009-10-15:

我将我的Ubuntu系统的默认编码更改为latin1.现在我可以用编辑器打开签出文件,它们看起来很好(感谢superuser.com上的@ John-T ).

但哈德森仍然抱怨unmappable character for encoding ASCII,我发现这是由maven引起的.我发现了一个explantion,但建议的解决方案没有奏效.现在maven告诉我它latin1在复制一些资源时会使用,但是编译器(不使用这个设置?)​​仍然会抱怨同样的错误信息.

Pas*_*ent 18

不,maven编译器插件不使用该project.build.sourceEncoding属性.所以你需要为它配置文件编码(我使用UTF-8):

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <encoding>UTF-8</encoding>
  </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

  • 或者,您可以使用`<encoding> $ {project.build.sourceEncoding} </ encoding>` (3认同)