简体   繁体   English

在 Spring 引导 Maven 项目中创建精简 jar 时出现问题

[英]Problem creating a thin jar in Spring Boot Maven project

I have a Maven Spring Boot Micro Services Java project arranged into a parent module and 6 sub-modules.我有一个 Maven Spring 引导微服务 Java 项目安排成一个父模块和 6 个子模块。 In the parent pom.xml, I have included the Maven Spring Boot Plugin in the build/plugins section: -在父 pom.xml 中,我在构建/插件部分包含了 Maven Spring 引导插件:-

    <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我的 6 个子模块中有 5 个是微服务,上面的插件确保这些被内置到可执行 Spring 启动 jars 中,包括所有依赖项,当我运行mvn clean install

However, the other sub-module is just a standard Java utility project and does not have a Spring Boot context.但是,另一个子模块只是一个标准的 Java 实用程序项目,没有 Spring 引导上下文。 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.这是意料之中的,因为该子模块不是 Spring 引导应用程序,并且没有主 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: -我试图通过覆盖该子模块的 pom 文件中的 Spring 引导 Maven 插件来解决此问题,以便将其视为标准的“瘦” Z68995FCBF432492D15484D04A9D2AC4

        <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.但是,我在 Maven 构建中仍然看到完全相同的错误。 I would be most grateful for any hints or pointers on this one.我将非常感谢有关此问题的任何提示或指示。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM