2019正月初一排查maven无厘头问题

15 篇文章 0 订阅
2 篇文章 0 订阅

今天是2019年正月初一,看到另一个角度拍摄的,助理在众多“现场观众”的注视下,帮刘谦变更道具的魔术,无趣。还是按计划把我的微服务项目往前推进一下吧。

我的微服务项目包括几个module,服务注册、服务提供者、服务消费者、安全、配置中心、负载均衡、路由。已经编写完毕,现在需要打成jar包,用docker部署到CentOS。千山万水都过去了,居然在maven打包时出现点异常。

在module bill-recharge-facade 打包时,提示如下:

$ mvn clean package
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Malformed POM D:\studies\billparent-all\bill-recharge-facade\pom.xml: expected START_TAG or END_TAG not TEXT (position: TEXT seen ...<!--\n    -->\n    <d... @18:7)  @ D:\studies\billparent-all\bill-recharge-facade\pom.xml, line 18, column 7
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-resources-plugin is missing. @ com.zkld.bill:billparent-all:1.0-SNAPSHOT, D:\studies\billparent-all\pom.xml, line 115, column 21
 @
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project com.zkld.bill:bill-recharge-facade:1.0-SNAPSHOT (D:\studies\billparent-all\bill-recharge-facade\pom.xml) has 1 error
[ERROR]     Malformed POM D:\studies\billparent-all\bill-recharge-facade\pom.xml: expected START_TAG or END_TAG not TEXT (position: TEXT seen ...<!--\n    -->\n    <d... @18:7)  @ D:\studies\billparent-all\bill-recharge-facade\pom.xml, line 18, column 7 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/ModelParseException

pom.xml文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>billparent-all</artifactId>
        <groupId>com.zkld.bill</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>bill-recharge-facade</artifactId>
      
    <!-- 当前Module需要用到的jar包,按自己需求添加,如果父类已经包含了,可以不用写版本号 -->
    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
            <version>1.4.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.46</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.8.1</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <!--Mybatis-generator插件,用于自动生成Mapper和POJO-->
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <!--配置文件的位置-->
                    <configurationFile>generator_bill.xml</configurationFile>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
                <executions>
                    <execution>
                        <id>Generate MyBatis Artifacts</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>1.3.2</version>
                    </dependency>

                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.46</version>
                    </dependency>

                </dependencies>
            </plugin>
        </plugins>

    </build>

</project>

在idea中打开pom.xml,有如下报错:

Element 'project' cannot have character [children], because the type's content type is element-only.

pom.xml

 结合maven命令行的提示,判断是pom.xml中有无素没有关闭,即要么没有开始,要么没有结束。逐个查每个元素,未见异常。很有可能是有特殊字符,给我们显示了空白符。经查pom.xml也是utf-8编码。对于此类无厘头的问题,通常有三个办法解决

1、新建一个空白的pom.xml,毫无保留的逐个字符再敲一遍进去,千万不要拷贝,因为你拷进去的代码可能包含了伪装的特殊字符。

2、分块查找法快速定位(找一个可以正常使用的pom.xml),逐块拷贝,采用类似二分查找法,快速定位问题。千万不要丢下原始pom.xml的任何一个字符不替换。否则找不到问题在哪块代码。

3、对于字符编码类的问题,还有一个简便的排查方法,即直接用记事本打开pom.xml,以ANSI编码保存,直接让“空白字符”现了原形。

对本例,我采用第3个办法,将pom.xml,以ANSI编码保存后,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>billparent-all</artifactId>
        <groupId>com.zkld.bill</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>bill-recharge-facade</artifactId>
    ??
    <!-- ��ǰModule��Ҫ�õ���jar�������Լ�������ӣ���������Ѿ������ˣ����Բ���д�汾�� -->
    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
            <version>1.4.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.46</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.8.1</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <!--Mybatis-generator���,�����Զ�����Mapper��POJO-->
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <!--�����ļ���λ��-->
                    <configurationFile>generator_bill.xml</configurationFile>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
                <executions>
                    <execution>
                        <id>Generate MyBatis Artifacts</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>1.3.2</version>
                    </dependency>

                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.46</version>
                    </dependency>

                </dependencies>
            </plugin>
        </plugins>

    </build>

</project>

就是它!位于<artifactId>bill-recharge-facade</artifactId>之后的两个问号单独占了一行(第13行)。可能是打汉字时,不小心输入的两个全角空格。肯定是非法的。删除后,问题解决。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值