使用 Maven 从 war 项目构建 jar 库?

发布于 2025-01-10 18:22:18 字数 907 浏览 0 评论 0原文

我们有一个 EAR 项目,其中有一个 WAR 项目。使用的是Maven,所以pom.xml。与任何项目一样,该项目还包含一个重要功能(例如作业调度“JBS”)以及许多其他功能。由于计划在不久的将来停用整个项目,因此不建议在该项目上投入大量资金(无论是错误还是增强)。

因此,为了将 (JBS) 功能作为单独的应用程序运行,复制了整个 EAR 项目(也是为了节省时间/成本)。结果,所有 Java 包和类(JBS 项目必需的)都被复制。在这种情况下,如果我们更新主项目中的一个或多个类,则此 (JBS) 功能项目/应用程序就会过时(并且需要更新)。

事实上,这个 JBS 功能项目仅需要许多 Java 类包(来自主 EAR-WAR 项目),并且不需要 99% 的 Web 模块和其他模块。我正在从 JBS 项目中删除所有不必要的东西。然后我想创建一个包含所有java类的JAR库,这样JBS项目就可以依赖这个JAR。

我不知道将这些类从主项目中分离出来(以创建另一个 Java 项目)是否是一个好主意。我想继续将这些课程作为主要项目的一部分。然后,这将是一件好事,因为当这些类中的一个或多个发生更改时,将生成新版本的 JAR(立即)。然后 JBS 项目将使用这个更新的 JAR。

我们怎样才能做到这一点?我明白,通过 Maven,我们可以在这种性质的项目上构建/打包 jar/war/ear。我不是maven专家(也没有系统学习)。

但是,有没有一种方法可以从 WAR pom.xml 中另外创建一个或多个 JAR?换句话说:我的意思是 WAR 的 pom.xml 将创建一个 WAR。除了创建 WAR 之外,maven 还可以帮助创建额外的 JAR 吗?或者maven可以从一个pom.xml创建两个包吗?

或者我应该在主项目中使用所有这些包/类创建一个单独的模块,并拥有自己的 pom.xml 来生成必要的 JAR?为此,我很可能需要修改主项目的结构。我想避免这种情况,除非没有出路。

你能给建议吗?

We have a EAR project which has a WAR project. Maven is used, so pom.xml. As typical of any project, this project also contains a big feature (say Job Scheduling "JBS") among many other features. As it is planned to retire this whole project in the near future, it is discouraged heavily to spend much on working on this project (whether bugs or enhancements).

Therefore, for the sake of running the (JBS) feature as a separate application, the whole EAR project was duplicated (also to save time/cost). As a result, all the Java packages and classes (necessary for JBS project) were duplicated. In this situation, if we update one or more classes in the main project, this (JBS) feature project/application gets outdated (and needs update).

The fact is that this JBS feature project ONLY requires many packages of Java classes (from the main EAR-WAR project), and do not require 99% of the web modules and others. I am removing all the unnecessary things from JBS project. Then I would like to create a JAR library with all the java classes, so JBS project can have a dependency on this JAR.

I do not know if it is a good idea to separate these classes out of the main project (to create another Java project). I would like to continue to have these classes as part of the main project. Then, it will be good, as and when one or more of these classes are changed, a new version of the JAR will be generated (right away). And the JBS project would then make use of this updated JAR.

How can we accomplish this? I understand, through maven, we can do a build/package jar/war/ear on a project of that nature. I am not an expert with maven (and did not learn it systematically).

But, is there a way to create one or more JARs additionally from inside WAR pom.xml? In other words: I mean pom.xml of WAR will create a WAR. In addition to creating a WAR, can maven help create additional JAR? Or can maven create two packages out of one pom.xml?

Or should I create a separate module in the main project with all these packages/classes, and have its own pom.xml to generate the necessary JAR? For this, most probably I need to modify the structure of the main project. I would like to avoid this unless there is no way out.

Can you advice?

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

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

发布评论

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

评论(1

白色秋天 2025-01-17 18:22:18

对您来说最好的事情似乎是创建一个包含 JAR 和其他项目的多模块项目。这样,您可以轻松地一起更改/构建它们,但您可以创建单独的工件。

It seems like the best thing for you would be to create a multi-module project that both contains the JAR and the other project. This way, you can easily change/build them together, but you create separate artifacts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文