如何使用Maven构建Spring Boot应用程序的库jar。

huangapple 未分类评论43阅读模式
英文:

How a build library jar of spring boot application using maven

问题

我有一个名为A的应用程序,其中包含从数据库获取记录的代码和一些其他功能。我想在另一个名为B的项目中使用相同的代码,并将A用作依赖。尽管不推荐将Spring Boot应用程序用作库,但我有这个用例,因为应用程序A是批处理应用程序,不会持续运行,因此没有REST调用的选项。
问题在于,当我尝试创建jar文件时,它会被创建为Spring Boot的jar文件,或者如果我创建普通jar文件,则没有必需的依赖项,导致在运行时失败,因为找不到类。
似乎在创建jar文件时未包括来自A的父项目的依赖项。
是否有一种推荐的使用Maven生成jar文件的方法。

英文:

I have an application A which contains code to fetch records from dB and some other functionality. I want to use the same in another project B and use A as dependency. Even if spring boot apps are not recommended to be used as library I have this use case bcs app A is a batch application and doesn’t keep running so no option of rest call.
Issue is when I try to create the jar it is created as spring boot jar or if I create a normal jar it doesn’t have the required dependencies and fails at runtime as class not found.
It seems dependencies from parent project of A are not included during jar creation.
Is there a recommenced way of generating the jar using maven.

答案1

得分: 0

为了详细说明chrylis所说的:

创建一个项目或模块C,其中包含A和B都需要的所有内容。在A和B中使用它作为依赖。

处理这个问题最简单的方法是创建一个多模块项目,包括A、B和C,但你也可以有三个单独的项目。

英文:

To elaborate on what chrylis said:

Create a project or module C that contains everything that both A and B need. Use it as dependency in A and B.

The easiest way to handle this is to have a multi-module-project with A, B and C, but you can also have three separate projects.

huangapple
  • 本文由 发表于 2020年4月5日 05:09:01
  • 转载请务必保留本文链接:https://java.coder-hub.com/61034826.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定