windows 如何在具有不同编码的异构环境中使用 maven?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1562843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Howto use maven in a heterogenous environment with different encodings?
提问by tangens
I've created a svn repositoy on a linux server (Debian) and used a client on a windows machine to check my java sources in.
我在 linux 服务器(Debian)上创建了一个 svn repositoy,并在 Windows 机器上使用了一个客户端来检查我的 java 源代码。
Now I've set up a Hudson server on a different linux server (Ubuntu) to periodically run tests on my code. But the tests fail with a compiler error:
现在我已经在不同的 linux 服务器 (Ubuntu) 上设置了一个 Hudson 服务器来定期对我的代码运行测试。但是测试失败并出现编译器错误:
Error: unmappable character for encoding ASCII
On my windows machine I've used the default encoding Cp1252. On my svn server I can do a local checkout of my sources and they look good. On my Hudson server the checkout contains illegal characters.
在我的 Windows 机器上,我使用了默认编码 Cp1252。在我的 svn 服务器上,我可以对我的源进行本地检出,它们看起来不错。在我的 Hudson 服务器上,结帐包含非法字符。
What are the parameters I have to adjust so that all three systems use a working encoding?
我必须调整哪些参数才能使所有三个系统都使用工作编码?
EDIT 2009-10-15:
编辑 2009-10-15:
I changed the default encoding of my Ubuntu system to latin1
. Now I can open the checkedout files with an editor and they look good (thanks to @John-T at superuser.com).
我将 Ubuntu 系统的默认编码更改为latin1
. 现在我可以使用编辑器打开检出文件,它们看起来不错(感谢superuser.com上的 @John-T )。
But Hudson still complained about unmappable character for encoding ASCII
and I found that this is caused by maven. I found an explantion, but the suggested solution didn't work. Now maven tells me that it uses latin1
when copying some resources, but the compiler (not using this setting?) still complains with the same error message.
但是Hudson还是抱怨unmappable character for encoding ASCII
,我发现这是maven造成的。我发现了一个explantion,但建议的解决方案没有奏效。现在 maven 告诉我它latin1
在复制某些资源时使用,但编译器(不使用此设置?)仍然抱怨相同的错误消息。
回答by Pascal Thivent
No, the maven compiler plugin doesn't use the project.build.sourceEncoding
property. So you need to configure the file encoding for it (I'd use UTF-8):
不,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>
回答by Chris J
The first thing to identify is which character is causing the problem. It may be that the broken char can be replaced by some pure-ASCII entity. SVN itself is encoding agnostic: it'll just store byte-for-byte what's passed in.
首先要确定是哪个字符导致了问题。可能是损坏的字符可以被一些纯 ASCII 实体替换。SVN 本身与编码无关:它只会逐字节存储传入的内容。
If Hudson requires 7-bit ASCII, then this is all you can do. Otherwise, find out what Hudson supports and save your files in this format instead. UTF-8 would probaby be the way to go.
如果 Hudson 需要 7 位 ASCII,那么这就是您所能做的。否则,请找出 Hudson 支持的内容并将文件保存为这种格式。UTF-8 可能是要走的路。
回答by the_mandrill
I don't think there is a way to change the encoding of a file with SVN. You can set the encoding for a commit message with the --encoding
flag, but not the contents of files themselves. Text files are stored in the same format they appear on your local disk. The only conversion is a translation of line endings according to the svn:eol-style property.
我认为没有办法用 SVN 更改文件的编码。您可以使用--encoding
标志设置提交消息的编码,但不能设置文件本身的内容。文本文件以它们出现在本地磁盘上的相同格式存储。唯一的转换是根据 svn:eol-style 属性转换行尾。