Maven:pom.xml文件解析异常

  • 问题描述

pom.xml文件格式不规范且使用格式化无法解决问题

  • 报错信息

  1. expected START_TAG or END_TAG not TEXT (position: TEXT seen ...<dependencies>\r\n \ua0\ua0\ua0\ua0\ua0<d... @18:16)

  2. 报错信息翻译:开始标签或结束标签不规范,在第18行第16个字符(@18:16),出现\ua0\ua0\ua0\ua0\ua0(不间断空格的unicode编码)

 

  • 解决方案

  1. 参考代码:
    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;
        }

     

  2. 双击选中,复制到pom.xml,再使用格式化(Ctrl+Shift+f),就能解析成功。
  • 参考文档:

  1. https://issues.apache.org/jira/browse/MNG-5848?focusedCommentId
  2. https://blog.csdn.net/u011389474/article/details/52931964
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值