springboot多模块引用 打包项目

场景:springboot构建多模块helloserviceapi和helloservice,其中helloservice引用helloserviceapi的jar包,打包B模块时报错,如下:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project hello-service: Compilation failure: Compilation failure: 
[ERROR] /D:/WorkSpace/IntelliJIDEA/spring-cloud/spring-cloud/hello-service/src/main/java/com/example/helloservice/Controller/RefactorHelloController.java:[3,39] �����com.example.helloserviceapi.dto������
[ERROR] /D:/WorkSpace/IntelliJIDEA/spring-cloud/spring-cloud/hello-service/src/main/java/com/example/helloservice/Controller/RefactorHelloController.java:[4,43] �����com.example.helloserviceapi.service������
[ERROR] /D:/WorkSpace/IntelliJIDEA/spring-cloud/spring-cloud/hello-service/src/main/java/com/example/helloservice/Controller/RefactorHelloController.java:[14,49] �Ҳ�������
[ERROR]   ����: �� HelloService
[ERROR] /D:/WorkSpace/IntelliJIDEA/spring-cloud/spring-cloud/hello-service/src/main/java/com/example/helloservice/Controller/RefactorHelloController.java:[21,12] �Ҳ�������
[ERROR]   ����:   �� User
[ERROR]   �: �� com.example.helloservice.Controller.RefactorHelloController
[ERROR] /D:/WorkSpace/IntelliJIDEA/spring-cloud/spring-cloud/hello-service/src/main/java/com/example/helloservice/Controller/RefactorHelloController.java:[26,38] �Ҳ�������
[ERROR]   ����:   �� User
[ERROR]   �: �� com.example.helloservice.Controller.RefactorHelloController
[ERROR] -> [Help 1]


出现乱码,但是没有找到解决乱码的办法,但是从百度的结果看,应该是提示 程序包com.example.helloserviceapi.dto不存在

解决办法:修改helloserviceapi模块中maven插件配置

原来配置

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

修改后配置

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                 <-- 添加内容 -->
                <configuration>
                    <classifier>exec</classifier>
                </configuration>
            </plugin>
        </plugins>
    </build>

原理:

spring boot工程打包编译时会生成两种jar包,一种是普通的jar,一种是可执行的jar。默认情况下,两个jar包名称相同,在不做配置的情况下,普通的jar先生成,可执行的jar后生成,所以可执行jar会覆盖普通的jar。我们在项目引用时,需要的是普通的jar,不需要可执行的jar。

参考链接:https://www.cnblogs.com/ITPower/p/10015471.html

注:如果哪位大佬解决了打包后控制台乱码的情况,请告知,谢谢!

发布了19 篇原创文章 · 获赞 15 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/minion_banana/article/details/100974907