【Exception】spring-boot-maven-plugin 打包多模块项目 BUILD FAILURE 集锦

本文详细解析了SpringBoot项目中子工程依赖失败的问题,特别是在Maven打包时出现的“程序包不存在”错误,提供了具体的配置修改方案,确保子工程能够正确引用父工程中的通用工具类。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目结构如下:

parent(父类工程)
	| - - - common(通用工具类子工程)
	| - - - projectA(springboot子工程,依赖common工程)

1、程序包XXX不存在

问题描述:

通过parent父工程进行Maven install,parent父工程和common子工程打包成功,projectA子工程打包失败并报错

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project client: Compilation failure: Compilation failure:
[ERROR] /E:/code/aden/check-system/client/src/main/java/com/aden/controller/LoginController.java:[3,24] 程序包com.aden.service不存在
[ERROR] /E:/code/aden/check-system/client/src/main/java/com/aden/controller/LoginController.java:[31,13] 找不到符号

注意:就算projectA能打包成功,运行后调用,也会报common下的类找不到异常,为同一问题

关键错误信息截图:
在这里插入图片描述
解决方案:

在common子工程下的pom.xml,添加以下配置

<build>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
			<configuration>
				<!--给可执行jar包添加后缀,防止和编译jar包重名导致覆盖了编译jar包,使依赖的模块编译失败-->
				<classifier>exec</classifier>
			</configuration>
		</plugin>
	</plugins>
</build>

原因分析:

common也是SpringBoot工程,SpringBoot工程打包编译时,会生成两种jar包,一种是普通的jar,另一种是可执行jar。
默认情况下,这两种jar的名称相同,在不做配置的情况下,普通的jar先生成,可执行jar后生成,造成可执行jar会覆盖普通的jar。而projectA工程无法依赖common工程的可执行jar,所以编译失败:程序包xxx不存在。

添加配置后截图如下,其中common-1.0-SNAPSHOT-exec.jar为可执行jar,common-1.0-SNAPSHOT.jar为普通jar包。
在这里插入图片描述

2、Unable to find main class

错误信息:
在这里插入图片描述
解决方案:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
            	<!--设置入口函数-->
                <mainClass>com.aden.Application</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>
D:\springboot\hspedu_springboot_vue>mvn org.springframework.boot:spring-boot-maven-plugin:run [INFO] Scanning for projects... Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/maven-metadata.xml Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/maven-metadata.xml (7.2 kB at 2.6 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/3.1.0/spring-boot-maven-plugin-3.1.0.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/3.1.0/spring-boot-maven-plugin-3.1.0.pom (3.2 kB at 4.1 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/3.1.0/spring-boot-maven-plugin-3.1.0.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/3.1.0/spring-boot-maven-plugin-3.1.0.jar (130 kB at 108 kB/s) [INFO] [INFO] ------------------< org.apache.maven:standalone-pom >------------------- [INFO] Building Maven Stub Project (No POM) 1 [INFO] --------------------------------[ pom ]--------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 6.851 s [INFO] Finished at: 2023-05-31T00:33:26+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.1.0:run (default-cli): Goal requires a project to execute but there is no POM in this directory (D:\springboot\hspedu_springboot_vue). Please verify you invoked Maven from the correct directory. -> [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/MissingProjectException怎么解决
05-31
"C:\Program Files\Java\jdk-17\bin\java.exe" -Dmaven.multiModuleProjectDirectory=D:\workspace-pro\mall\font-mall-boot -Djansi.passthrough=true -Dmaven.home=D:\tools\apache-maven-3.8.4 -Dclassworlds.conf=D:\tools\apache-maven-3.8.4\bin\m2.conf "-Dmaven.ext.class.path=C:\Program Files\JetBrains\IntelliJ IDEA 2023.3.6\plugins\maven\lib\maven-event-listener.jar" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2023.3.6\lib\idea_rt.jar=58294:C:\Program Files\JetBrains\IntelliJ IDEA 2023.3.6\bin" -Dfile.encoding=UTF-8 -classpath D:\tools\apache-maven-3.8.4\boot\plexus-classworlds-2.6.0.jar;D:\tools\apache-maven-3.8.4\boot\plexus-classworlds.license org.codehaus.classworlds.Launcher -Didea.version=2023.3.6 -s D:\tools\apache-maven-3.8.4\conf\settings.xml -Dmaven.repo.local=D:\tools\mvnRepo_1.1 -DskipTests=true com.spotify:docker-maven-plugin:1.2.2:build -P rdc,pre,!test [INFO] Scanning for projects... [WARNING] [WARNING] Some problems were encountered while building the effective model for com.reeji:font-mall-boot:jar:1.0-SNAPSHOT [WARNING] 'build.plugins.plugin.version' for org.springframework.boot:spring-boot-maven-plugin is missing. @ line 180, column 21 [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. [WARNING] [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. [WARNING] [INFO] [INFO] ----------------------< com.reeji:font-mall-boot >---------------------- [INFO] Building font-mall-boot 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- docker-maven-plugin:1.2.2:build (default-cli) @ font-mall-boot --- [INFO] Using authentication suppliers: [ConfigFileRegistryAuthSupplier] [INFO] Copying D:\workspace-pro\mall\font-mall-boot\target\font-mall-boot-1.0-SNAPSHOT.jar -> D:\workspace-pro\mall\font-mall-boot\target\docker\font-mall-boot-1.0-SNAPSHOT.jar [INFO] Copying D:\workspace-pro\mall\font-mall-boot\target\classes\docker\Dockerfile -> D:\workspace-pro\mall\font-mall-boot\target\docker\Dockerfile [INFO] Building image font-mall-boot Step 1/11 : FROM adoptopenjdk/openjdk11 as builder ---> 82de38fa2bb6 Step 2/11 : WORKDIR application ---> Using cache ---> 9c3dec2fcc03 Step 3/11 : ADD . . ---> 4ca0dbfb3ed9 Step 4/11 : RUN java -Djarmode=layertools -jar font-mall-boot-1.0-SNAPSHOT.jar extract ---> Running in 737deb4e4a34 no main manifest attribute, in font-mall-boot-1.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 5.736 s [INFO] Finished at: 2025-08-04T14:57:11+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.2.2:build (default-cli) on project font-mall-boot: Exception caught: The command '/bin/sh -c java -Djarmode=layertools -jar font-mall-boot-1.0-SNAPSHOT.jar extract' returned a non-zero code: 1 -> [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/MojoExecutionException Process finished with exit code 1
最新发布
08-05
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值