且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

é变成& 195;#169,然后变成é如何解决此编码问题?

更新时间:2023-11-20 21:08:04

也许Eclipse正在使用与Maven不同的javac命令行来编译文件.

Perhaps Eclipse is compiling the file with a different javac command line than Maven.

编译Java时,必须告诉编译器源文件的编码(如果它们包含非ASCII字符,并且默认设置不起作用).

When you compile Java, you have to tell the compiler the encoding of the source files (if they contain non-ASCII characters and the default doesn't work).

javac -encoding utf8 MyCode.java

认为在Maven中解决此问题的方法是将其添加到您的pom.xml文件中:

I think the way to fix this in Maven is to add this to your pom.xml file:

<project>
  ...
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  ...
</project>

(我是从关于一个稍微不同的问题的Maven常见问题解答中获得的. )

您可以通过在Java文件中使用丑陋的Unicode转义序列来完全避免编码问题. é将成为\u00e9.对人类来说更糟,对烤面包机来说更容易. (正如Perlis所说,在人机共生中,必须由人来调整:机器不能."

You could instead avoid the encoding issue entirely by using ugly Unicode escape sequences in your Java file. é would become \u00e9. Worse for humans, easier for the toasters. (As Perlis said, "In man-machine symbiosis, it is man who must adjust: The machines can't.")