我目前正在处理遗留代码。该项目是一个基于 maven 的大型项目,其中一项任务是更改编码,从 cp1252 到 utf-8 .ie
<project.build.sourceEncoding>cp1252</project.build.sourceEncoding>
到
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
大部分代码已经是 utf-8,但有些 xml 文件不是,(并且它们的 header 为 <?xml version="1.0" encoding="ISO-8859-1"?>.
)
我是否必须手动将所有这些文件的标题更改为 utf-8,或者只需将 Maven 中的设置更改为 UTF-8 就可以正常工作?我想这样做会有很多可能损坏的字符?
最佳答案
Currently, the character encoding for source files needs to be configured individually for each and every plugin that processes source files. In this context, source file refers to some plain text file that - unlike an XML file - lacks intrinsic means to specify the employed file encoding. The Java source files are the most promiment example of such text files. Velocity templates, BeanShell scripts and APT documents are further examples. This proposal does not apply to XML files as their encoding can be determined from the file itself, see XML encoding for further information.
关于java - 在 Maven 项目中更改编码(CP-1252 到 UTF-8)时,我应该如何处理编码为 iso-8859-1 的 XML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18758588/