MAVEN INSTALL时报错 程序包不存在以及找不到类的情况

原文连接:https://blog.csdn.net/qq_38408785/article/details/103046252

今天用maven做微服务项目时 报错

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project ly-item-interface: Compilation failure: Compilation failure:
[ERROR] /D:/javacode/idea/leyou/ly-item/ly-item-interface/src/main/java/com/leyou/item/api/GoodsApi.java:[3,28] 程序包com.leyou.common.dto不存在
[ERROR] /D:/javacode/idea/leyou/ly-item/ly-item-interface/src/main/java/com/leyou/item/api/GoodsApi.java:[4,27] 程序包com.leyou.common.vo不存在
[ERROR] /D:/javacode/idea/leyou/ly-item/ly-item-interface/src/main/java/com/leyou/item/api/GoodsApi.java:[23,5] 找不到符号
[ERROR] 符号:   类 PageResult
[ERROR] 位置: 接口 com.leyou.item.api.GoodsApi
[ERROR] /D:/javacode/idea/leyou/ly-item/ly-item-interface/src/main/java/com/leyou/item/api/GoodsApi.java:[37,42] 找不到符号
[ERROR] 符号:   类 CartDTO
[ERROR] 位置: 接口 com.leyou.item.api.GoodsApi
[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
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :ly-item-interface

Process finished with exit code 1


1. 根本原因(以其中一个ERROR为例分析)

ly-item-interface: Compilation failure: Compilation failure:
[ERROR] com/leyou/item/api/GoodsApi. 程序包com.leyou.common.dto不存在

ly-item-interface: Compilation failure: Compilation failure:
[ERROR] com/leyou/item/api/GoodsApi.  程序包com.leyou.common.dto不存在

ly-item-interface在打包时要依赖com.leyou.common包
就很奇怪 明明这个包这个类都是存在的啊,为什么就是找不到???
其次做了几项检查:

pom.xml依赖是否成功引入或者存在不存在单词拼写错误(一般情况不会有错啊)
common包中dto是否成功import (这么简单必然成功import了啊…)

2 解决办法

最终原因,其实就是没有依赖。。。原因就是spring-boot-maven-plugin
这个坑!!!用这个插件打包的Jar包可以直接运行,但是不可依赖!!!所以interface自始至终就没有依赖,自然会说找程序包不存在或者找不到类

最后修改pom.xml的依赖:

 <build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <classifier>execute</classifier>
            </configuration>
        </plugin>
    </plugins>
 </build>

3 总结

一个微服务通常有两个子module,一般一个写实体类和接口一个写实现方法

建议

common类或者实体类或者被被依赖的类,打包插件配置为:

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>none</phase>
                    </execution>
                </executions>
                <configuration>
                    <classifier>execute</classifier>
                </configuration>
            </plugin>
        </plugins>
</build>

注意:

<executions>
    <execution>
        <phase>none</phase>
    </execution>
</executions>

是为了解决Unable to find main class的问题,当然,如果写了简单的main函数这几行可以不写~

其他类或者微服务可以正常配置:

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
</build>

4 最后

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值