Maven:合并 Web 项目

发布于 2024-08-18 05:07:03 字数 728 浏览 6 评论 0 原文

我设置了以下 Maven 项目:

  • PM-Core
  • PM-Web(依赖于 PM-Core)
Now, this project is used for several clients but for each client there are some small differences: mostly differences in configuration files but some clients also require additional java files (which may not be installed for the other clients).

我一直在考虑如何使用 Maven 支持此功能的几种替代方案,但仍在寻找完美的解决方案。

我能想到的最好的解决方案是为每个客户端创建一个单独的maven项目(例如PM-CLIENT1,...),其中仅包含客户端特定的配置文件和附加的java文件或jsp,...。下一步是将 PM-Web 项目和客户端项目视为一个 Web 项目,这意味着:将它们组合(打包)到 1 个 war 文件中,其中客户端项目中的文件优先于 PM-Web 项目中的文件。

更具体地说:在 PM-Client1 上运行 mvn package 将从 PM-Web 获取所有内容,添加/替换 PM-Client1 中的文件,然后将其打包到单个 war 中。

那么问题来了:如何用maven来实现呢?

I have following Maven projects set up:

  • PM-Core
  • PM-Web (with a dependency to PM-Core)

Now, this project is used for several clients but for each client there are some small differences: mostly differences in configuration files but some clients also require additional java files (which may not be installed for the other clients).

I've been considering several alternatives on how to support this with maven but am still looking for the perfect solution.

The best solution I can think of is to create a separate maven project for each client (e.g. PM-CLIENT1, ...) which contains only the client specific configuration files and additional java files or jsp's, ... . Next step would be to consider the PM-Web project and the client project as one web project, meaning: have them combined (packaged) into 1 war file with files from the client project having precedence over files from the PM-Web project.

More concrete: running mvn package on PM-Client1 would take everything from PM-Web, add/replace the files from PM-Client1 and then package this into a single war.

So the question is: how to achieve this with maven?

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

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

发布评论

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

评论(3

森林迷了鹿 2024-08-25 05:07:03

是的,这可以使用覆盖来完成。网页上的示例正是您所说的。

对于项目结构,您可以有这样的内容:

.
|-- PM-Core
|-- PM-WebCommon (of type war, depends on core)
|-- PM-Client1 (of type war, depends on webcommon)
`-- PM-Client2 (of type war, depends on webcommon)

并在 PM-Client1 和 PM-Client2 中使用覆盖将它们与 PM-WebCommon 进行“合并”,并为每个客户端打包 wars。

更新我不会涵盖所有细节,但我认为在使用覆盖时需要使用runtime类型的范围声明战争依赖,这就是覆盖的工作原理(实际上,整个覆盖的事情是一种黑客)。现在,要解决 Eclipse 问题,一种解决方案是创建一个包含 PM-WebCommon 项目的类的 JAR。为此,请使用 attachClasses 可选参数并将其设置为 true。这将告诉 maven 创建一个 PM-WebCommon--classes.jar,然后您就可以将其声明为 PM-Client1 中的依赖项(使用 provided范围)。有关详细信息,请查看 MWAR-73MWAR-131。这也在战争的 FAQ 中进行了讨论插件。请注意,这不是推荐的做法,正确的方法是将类移动到单独的模块(这是我想提到的另一个解决方案)。

更新(201001018):我尝试过 attachClasses 参数,它适用于插件的 2.1-beta-1 版本。

Yes, this can be done using Overlays. The sample on the webpage is exactly what you are talking about.

For the project structure, you could have something like this:

.
|-- PM-Core
|-- PM-WebCommon (of type war, depends on core)
|-- PM-Client1 (of type war, depends on webcommon)
`-- PM-Client2 (of type war, depends on webcommon)

And use overlay in PM-Client1 and PM-Client2 to "merge" them with PM-WebCommon and package wars for each client.

UPDATE I won't cover all the details but I think that declaring the war dependency with a scope of type runtime is required when using overlay, this is how overlay do work (actually, the whole overlay thing is a kind of hack). Now, to solve your eclipse issue, one solution would be to create a JAR containing the classes of the PM-WebCommon project. To do so, use the attachClasses optional parameter and set it to true. This will tell maven to create a PM-WebCommon-<version>-classes.jar that you'll then be able to declare as dependency in PM-Client1 (with a provided scope). For the details, have a look at MWAR-73 and MWAR-131. This is also discussed in the FAQ of the war plugin. Note that this is not a recommended practice, the right way would be to move the classes to a separate module (and this is the other solution I wanted to mention).

UPDATE (201001018): I've tried the attachClasses parameter and it works with version 2.1-beta-1 of the plugin.

耀眼的星火 2024-08-25 05:07:03

您可以使用配置文件参见http://maven.apache.org/guides/mini/guide -building-for- different-environments.html 并使用 分类器 来区分同一版本的不同构建的工件。
在此设置中,您可以在父项目下为每个客户的特定自定义创建额外的可选模块,即
+ 下午
++ PM 核心
++ PM-Web
++ PM-客户端1
++ PM-Client2

或者您可以查看使用 maven 程序集插件

You could use profiles see http://maven.apache.org/guides/mini/guide-building-for-different-environments.html and use classifiers to distinguish between the artifacts from the different builds for the same version.
In this setup, you could create additional optional modules for each of your clients specific customisations under the parent project i.e.
+ PM
++ PM-Core
++ PM-Web
++ PM-Client1
++ PM-Client2

Or you could look at using use the maven assembly plugin

零崎曲识 2024-08-25 05:07:03

另请比较问题 不同 WAR 文件、共享资源 的答案。

Compare also the answers for question different WAR files, shared resources .

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