为什么建设营销型网站,帮别人制作网页多少钱,wordpress 邮件发送,视觉差 网站我执行 mvn install 报如下错误 可是我在 web 模块中能正确引用到 common 的类#xff0c;于是我把 web 引用到的 common 中的类先移动到 web 模块中#xff0c;然后把 common 模块的类都删掉#xff0c;然后再次执行 mvn install,结果报错如下#xff1a;
[ERROR] Faile…我执行 mvn install 报如下错误 可是我在 web 模块中能正确引用到 common 的类于是我把 web 引用到的 common 中的类先移动到 web 模块中然后把 common 模块的类都删掉然后再次执行 mvn install,结果报错如下
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.1.12:repackage (repackage) on project common: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:3.1.12:repackage failed: Unable to find main class - [Help 1]
[ERROR]这个问题的原因 Spring Boot 的 spring-boot-maven-plugin 插件的 repackage 目标需要在构建时指定一个主类main class用于创建可执行的 JAR 或 WAR 文件。如果你的 common 模块不是一个 Web 或 Spring Boot 应用它应该不需要这个插件的 repackage 目标因为它并没有主类main class可供启动。
我的项目结构
父模块 - tylerpro
tylerpro 的 pom.xml 内容
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion3.1.12/versionrelativePath/ !-- lookup parent from repository --/parentgroupIdcom.tylerpro/groupIdartifactIdtylerpro/artifactIdversion0.0.1/versionnametylerpro/namedescriptiontylerpro/descriptionpackagingpom/packagingmodulesmoduleweb/modulemodulecommon/module/modulesproperties/propertiesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdconfigurationexcludesexcludegroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/exclude/excludes/configuration/plugin/plugins/build
/project子模块 - common
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.tylerpro/groupIdartifactIdtylerpro/artifactIdversion0.0.1/version/parentgroupIdcom.tylerpro/groupIdartifactIdcommon/artifactIdversion0.0.1/versionpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/properties
/project子模块 - web
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.tylerpro/groupIdartifactIdtylerpro/artifactIdversion0.0.1/version/parentgroupIdcom.tylerpro/groupIdartifactIdweb/artifactIdnameweb/namedescriptionweb/descriptionproperties/propertiesdependenciesdependencygroupIdcom.yxai/groupIdartifactIdcommon/artifactIdversion0.0.1/version/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdconfigurationexcludesexcludegroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/exclude/excludes/configuration/plugin/plugins/build
/project原因是 因为 common 模块中继承了父模块的打包插件而 common 模块只是作为一个普通的库使用它不是一个 springboot 项目。在父模块中使用了 spring-boot-maven-plugin 打包所以 common 打包出错了。
解决方案
因为 web 中已经使用了 spring-boot-maven-plugin 打包插件所以直接删除父模块中的打包插件就行。
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion3.1.12/versionrelativePath/ !-- lookup parent from repository --/parentgroupIdcom.tylerpro/groupIdartifactIdtylerpro/artifactIdversion0.0.1/versionnametylerpro/namedescriptiontylerpro/descriptionpackagingpom/packagingmodulesmoduleweb/modulemodulecommon/module/modulesproperties/properties扩展
maven 打包的几种方式 SpringBoot 使用 maven 创建一个可执行的 jar 包 - SpringBoot官方文档-Creating an Executable Jar apache maven plugin 打包插件 apache maven plugin 打包插件的属性配置 maven 高级视频教程