java - 在 Maven 项目中更改编码(CP-1252 到 UTF-8)时,我应该如何处理编码为 iso-8859-1 的 XML 文件

标签 java maven encoding utf-8 iso-8859-1

我目前正在处理遗留代码。该项目是一个基于 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 就可以正常工作?我想这样做会有很多可能损坏的字符?

最佳答案

doesn't apply to XML files :

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/

相关文章:

java - 文件编码的默认字符集 - Java

c# - silverlight/wpf 网页浏览器编码

java - 使用特殊编码将 Java String 写入文件

java - 重新启动 karaf 需要更新包

java - 使用 kotlin-maven-plugin 进行注解处理

java - 如何在java swing中生成这个布局

java - Gradle:从下载的 POM 中获取 Maven 存储库列表

maven - javax.servlet.HttpConstraintElement”的签名者信息与同一包内其他类的签名者信息不匹配

java - 使用 POI 事件模型将工作表写入文本文件

Java api 查找网络节点