-
问题描述
pom.xml文件格式不规范且使用格式化无法解决问题
-
报错信息
-
expected START_TAG or END_TAG not TEXT (position: TEXT seen ...<dependencies>\r\n \ua0\ua0\ua0\ua0\ua0<d... @18:16)
-
报错信息翻译:开始标签或结束标签不规范,在第18行第16个字符(@18:16),出现\ua0\ua0\ua0\ua0\ua0(不间断空格的unicode编码)
-
解决方案
- 参考代码:
public static void main(String[] args) { //将要添加的GAV坐标复制过来 String pomInfo = "<dependencyManagement>\n" + " <dependencies>\n" + " <dependency>\n" + " <groupId>org.springframework.cloud</groupId>\n" + " <artifactId>spring-cloud-dependencies</artifactId>\n" + " <version>Dalston.SR1</version>\n" + " <type>pom</type>\n" + " <scope>import</scope>\n" + " </dependency>\n" + " </dependencies>\n" + " </dependencyManagement>"; //PS:查看字符串的Unicode编码值方法: System.out.println(Integer.toHexString(" ".charAt(0)));//普通空格,\u0020 System.out.println(Integer.toHexString(" ".charAt(0)));//不间断空格,\u00a0 pomFormat(pomInfo); } /** * 格式化字符串,去掉所有的空格符、换行符 */ public static String pomFormat(String pomInfo) { pomInfo = pomInfo.replace("\n", "");//去掉换行符 pomInfo = pomInfo.replace(" ", "");//去掉普通空格,\u0020 pomInfo = pomInfo.replace("\u00A0", "");//去掉不间断空格,\u00a0 // pomInfo=pomInfo.replace(" ","");//去掉不间断空格,\u00a0 System.out.println("[" + pomInfo + "]"); return pomInfo; }
- 双击选中,复制到pom.xml,再使用格式化(Ctrl+Shift+f),就能解析成功。
-
参考文档: