gpt4 book ai didi

java - 使用 Spring-Boot 创建一个简单的 JAR 而不是可执行的 JAR

转载 作者:搜寻专家 更新时间:2023-10-31 08:25:28 25 4
gpt4 key购买 nike

我在使用多模块 Spring-Boot 应用程序时遇到问题。

我有一个用于服务的模块,即核心模块。还有一个用于 View 相关类的模块,即 web 模块。它们都在 parent-Module 中,我在其中添加了依赖项,例如“spring-boot-starter”,这两个模块都可以使用。

现在的问题:

我想使用嵌入式 Tomcat 运行 web-Module,并将 core-Module 作为 web-module 的依赖项.

在其他 Spring 项目中,我只包含 maven-jar-plugin 并创建一个 core-Module 的 jar。

这个 Spring-Boot 项目的问题是 maven-jar-plugin 已经在“spring-boot-starter”中配置好了。它需要一个 mainClass,只有 web 模块有。

“spring-boot-starter”-POM 的小摘录

            <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>${start-class}</mainClass>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>

有没有一种方法可以将核心模块打包为 JAR 而不需要该模块中的“启动类”?

最佳答案

您似乎可以通过配置 spring-boot-maven-plugin 来禁止 fat-JAR 替换原始文件并安装到 repo 中。

取自http://docs.spring.io/spring-boot/docs/1.5.1.RELEASE/maven-plugin/examples/repackage-disable-attach.html :

By default, the repackage goal will replace the original artifact with the executable one. If you need to only deploy the original jar and yet be able to run your app with the regular file name, configure the plugin as follows:

<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.1.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<attach>false</attach>
</configuration>
</execution>
</executions>
...
</plugin>
...
</plugins>
...
</build>
...
</project>

This configuration will generate two artifacts: the original one and the executable counter part produced by the repackage goal. Only the original one will be installed/deployed.

关于java - 使用 Spring-Boot 创建一个简单的 JAR 而不是可执行的 JAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38312448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com