英文:
Problem creating a thin jar in Spring Boot Maven project
问题
我有一个使用Maven构建的Spring Boot微服务Java项目,它被组织成一个父模块和6个子模块。在父模块的pom.xml文件中,我已经在build/plugins部分包含了Maven Spring Boot插件:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.5.RELEASE</version>
</plugin>
我的6个子模块中有5个是微服务,上面的插件确保在运行 mvn clean install
时,它们会被构建成可执行的Spring Boot可执行jar包,包括所有依赖项。
然而,另一个子模块只是一个标准的Java实用项目,没有Spring Boot上下文。当我尝试构建时,我看到以下错误:
Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.1.5.RELEASE:repackage failed: Unable to find main class -> [Help 1]
这是预期的,因为这个子模块不是一个Spring Boot应用程序,也没有主类。我尝试通过在该子模块的pom文件中覆盖Spring Boot Maven插件来修复这个问题,以便将其视为标准的 'thin' jar 包:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<!-- 以下启用了 "thin jar" 部署选项。 -->
<!-- 这将创建一个普通的jar文件,而不是可执行的Spring Boot jar文件。 -->
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-thin-layout</artifactId>
<version>1.0.11.RELEASE</version>
</dependency>
</dependencies>
</plugin>
然而,我在我的Maven构建中仍然看到完全相同的错误。对于这个问题,我将非常感激任何提示或指导。
英文:
I have a Maven Spring Boot Micro Services Java project arranged into a parent module and 6 sub-modules. In the parent pom.xml, I have included the Maven Spring Boot Plugin in the build/plugins section: -
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.5.RELEASE</version>
</plugin>
5 of my 6 sub-modules are Micro Services, and the above plugin ensures that these are built into executable Spring Boot jars, including all dependencies, when I run mvn clean install
However, the other sub-module is just a standard Java utility project and does not have a Spring Boot context. When I try to build, I see the following error: -
Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.1.5.RELEASE:repackage failed: Unable to find main class -> [Help 1]
This is expected as this sub-module is not a Spring Boot application and does not have a main class. I tried to fix this by overriding the Spring Boot Maven plugin in the pom file of that sub-module so that it is treated as a standard 'thin' jar: -
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<!-- The following enables the "thin jar" deployment option. -->
<!-- This creates a normal jar, not an executable springboot jar -->
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-thin-layout</artifactId>
<version>1.0.11.RELEASE</version>
</dependency>
</dependencies>
</plugin>
However, I am still seeing exactly the same error in my Maven build. I would be most grateful for any hints or pointers on this one.
答案1
得分: 1
你可以通过在该模块中覆盖配置来跳过实用模块的重新打包插件的执行。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
英文:
You can skip the execution of the repackage plugin for your utility module by overriding the configuration in that module.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论