Spring Boot“Thinner Fat Jar” - 将 jar 分成 2 个(应用程序/库)

发布于 2025-01-10 05:07:11 字数 305 浏览 0 评论 0原文

我想将我的应用程序分成 2 个胖罐子(模块/库)。

我已经检查过“Spring Boot Thin jar 项目”,它加载依赖项并在第一次运行时缓存它们,但我无法使其与多个本地模块一起使用。

不过...我更愿意让我的第一种方法发挥作用。有什么想法吗?

Gradle 6.9.1(7.x 不适用于 Thin jar)

Spring Boot 2.6.x

编辑 (2022-02)

检查下面的解决方案...

I would like to split my app into 2 fat jars (modules/libraries).

I've checked already the "Spring Boot thin jar project", which loads the dependencies and caches them on first run but I cant make it work with multiple local modules.

Still... I would prefer to make my first approach work. Any ideas?

Gradle 6.9.1 (7.x not working with thin jar)

Spring Boot 2.6.x

Edited (2022-02)

Check my solution below...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

余罪 2025-01-17 05:07:11
  • 创建2个项目,构建时构建为2个JAR文件。

  • 项目 1(fat JAR)对项目 2 的引用。

  • Spring Boot fat JAR(已嵌入 Tomcat),将调用另一个 JAR。

  • Create 2 projects, when build, build to 2 JAR file.

  • Project 1 (fat JAR) reference to Project 2.

  • Spring Boot fat JAR (has embed Tomcat), will call another JAR.

月牙弯弯 2025-01-17 05:07:11

我设法做了我想做的事。

为此,我必须将 gradle 中的 bootJar 任务扩展为 2 个任务,一个用于依赖项,另一个用于我的库......

task bootJarDeps(type: org.springframework.boot.gradle.tasks.bundling.BootJar) {
  description "Generates JAR with just dependencies."
  exclude 'com.mypackage.**.jar'
  archiveName 'deps.jar'

  mainClass = 'com.mypackage.App'
  with bootJar
}

依赖项中的 mainClass 没有用,但仍然是该任务所必需的。

task bootJarApp(type: org.springframework.boot.gradle.tasks.bundling.BootJar) {
  description "Generates JAR without dependencies."
  include 'com.mypackage.**.jar'
  mainClass = 'com.mypackage.App'
  archiveName 'app.jar'
  with bootJar
}

I managed to do what I wanted.

For that purpose, I had to extend the bootJar task in gradle into 2 tasks, one for the dependencies, and one for my libraries...

task bootJarDeps(type: org.springframework.boot.gradle.tasks.bundling.BootJar) {
  description "Generates JAR with just dependencies."
  exclude 'com.mypackage.**.jar'
  archiveName 'deps.jar'

  mainClass = 'com.mypackage.App'
  with bootJar
}

The mainClass in the dependencies is useless, but still required for the task.

task bootJarApp(type: org.springframework.boot.gradle.tasks.bundling.BootJar) {
  description "Generates JAR without dependencies."
  include 'com.mypackage.**.jar'
  mainClass = 'com.mypackage.App'
  archiveName 'app.jar'
  with bootJar
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文