java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > Maven parent.relativePath带给我的坑

解决Maven parent.relativePath带给我的坑

作者:蜀山小师叔

在Linux环境下使用Maven进行项目打包时,可能会遇到“当前目录没有pom文件”的错误,需要确认在包含pom.xml文件的项目目录下执行Maven命令,另外,如果遇到“parent.relativePath points at wrong local POM”错误,可能是父模块依赖问题

前言

东西很简单,只是作为一个记录给后面的兄弟。周末搞了Linux上使用Maven打包遇到的问题。如果忽略排查思路可直接看解决

问题

The goal you specified requires a project to execute but there is no POM in this directory (/data/my). Please verify you invoked Maven from the correct directory

spring-boot-starter-parent-2.2.2.RELEASE.pom and ‘parent.relativePath’ points at wrong local POM @ line 30, column 13

之后就提示:ModelParseException异常,然后提供[Help 1]

https://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException 这个网址,进去里面一看,说的是Parent父类依赖有问题。

但是,笔者的父模块的parent依赖是spring boot

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
</parent>

这里后面Spring考虑到了说,如果当前项目需要依赖的其他的项目,并且是以上层方式导入的,可以替换为

<dependencies>
            <!-- SpringBoot的依赖配置 -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.2.2.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
</dependencies>

这个与上面的parent是一样的效果。

具体网址

题外话了,这个是创建pom文件规范的问题。

因为这个pom文件,里面使用了parent注入spring的jar包,所以呢,就导致了parent.relativePath???笔者很疑惑,为什么呢?

因为这个项目在笔者的IDEA上运行是正常的,不可能说,放到Linux就挂掉了吧,连mvn clean 都报错。具体错误两个

spring-boot-starter-parent-2.2.2.RELEASE.pom and ‘parent.relativePath’ points at wrong local POM @ line 30, column 13

java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty -> [Help 2]

按照正常人的思维,我肯定是解决掉第一个再去解决第二个,是吧。

但是呢?笔者花了将近4个小时左右,

  1. 从maven的setting文件,阿里云的镜像,pom依赖是不是有问题
  2. 删掉了parent,重新拉取,还是不行
  3. jdk和maven是不是不匹配,对比了之后,是匹配的
  4. 重新拉了个自己的项目,结果居然爆java.security.InvalidAlgorithmParameterException

所以说排查问题得有思路,正常都是第一个之后再第二个吧,而且英语很重要啊。

security明显的权限问题,一查下去,发现是HTTPS在搞鬼。

看过一篇文章,说的是安全性的问题,有几种解决方法,但是笔者选择了快捷有效的。

直接忽略SSL安全检查,加载mvn package之后。

mvn package -Dmaven.test.skip=true -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true

之后运行,OK完成。

解决

绕过前面一大堆思路,看看报错问题是否存在java.security.InvalidAlgorithmParameterException,先把你maven拉取jar包的权限弄好再说。

直接在maven命令上加上忽略SSL安全检查

mvn package -Dmaven.test.skip=true -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true

总结

排查思路很重要啊,而且一些maven的常用命令没怎么去学习。最近有些懈怠了。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文