Maven打包错误找不到api依赖项目以及找不到符号

前言

本文作为:Maven打包项目及其遇到的问题解决方案的遇到的问题和解决方案补充。

找不到分布式项目所依赖的子项目api

以简单的demo项目为例:

[ERROR] Failed to execute goal on project dubbo-demo-consumer:Could not resolve dependencies for project com.imooc:dubbo-demo-consumer:jar:1.5.3.RELEASE: Could not find artifact com.imooc:dubbo-demo-api:jar:1.0-SNAPSHOT -> [Help 1]

解决方案

1、首先确认将api项目打包完成生成Jar:clean package -Dmaven.test.skip=true;


2、如果jar包已经packe完毕后,依旧找不到:Maven clean -> Maven install ;这里的install将会把api的jar包加载到maven仓库,这里后续打provider和consumer的包的时候才能找到api的jar

在这里插入图片描述

同步更新。打包还是用到.m2里面的jar。只要这里面的jar更新了即可。


3、如果遇到maven dependencies里面的without test code 关掉该依赖项目,会变成jar。或者对eclipse设置亦可。


4、打包API项目如果遇到:

[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

更换正确的JDK即可,我是直接在Window->preference->Java->Installed JREs->Add->jdk文件目录即可并选为默认。

在这里插入图片描述

成功信息我们可以看到打成的jar包存放在哪里,install将子项目api引入打到maven仓库地址中,可以在后续打provider和consumer的包的时候,作为pom的依赖被引入

在这里插入图片描述

找不到符号 && 方法不会覆盖或实现超类型的方法

COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] xxxServiceImp.java:[30,28] 错误: 找不到符号
[INFO] 7 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.567 s
[INFO] Finished at: 2021-03-11T16:45:08+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project xxxx: Compilation failure: Compilation failure:

[ERROR] xxxServiceImp.java:[51,1] 错误: 找不到符号
[ERROR] xxxServiceImp.java:[42,7] 错误: xxxServiceImp不是抽象的, 并且未覆盖xxxService中的抽象方法submitSqlJob(List<String>,List<String>,List<String>)

[ERROR] -> [Help 1]
[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/MojoFailureException


原因:

api的jar没更新,所以会报 ServiceImp无法实现覆盖Service里面的方法。

解决步骤:

1、重新打包api,build命令:clean package -Dmaven.test.skip=true;

2、引入新的api.jar到.m2maven仓库:mvn install api项目;

在这里插入图片描述

3、重新clean package -Dmaven.test.skip=true,打包provider和consumer文件;

猜你喜欢

转载自blog.csdn.net/qq_37334150/article/details/114694645
今日推荐