我设置了以下 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?
发布评论
评论(3)
是的,这可以使用覆盖来完成。网页上的示例正是您所说的。
对于项目结构,您可以有这样的内容:
并在 PM-Client1 和 PM-Client2 中使用覆盖将它们与 PM-WebCommon 进行“合并”,并为每个客户端打包 wars。
更新我不会涵盖所有细节,但我认为在使用覆盖时需要使用
runtime
类型的范围声明战争依赖,这就是覆盖的工作原理(实际上,整个覆盖的事情是一种黑客)。现在,要解决 Eclipse 问题,一种解决方案是创建一个包含 PM-WebCommon 项目的类的 JAR。为此,请使用attachClasses
可选参数并将其设置为
true
。这将告诉 maven 创建一个PM-WebCommon--classes.jar
,然后您就可以将其声明为 PM-Client1 中的依赖项(使用provided范围)。有关详细信息,请查看 MWAR-73 和 MWAR-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:
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 theattachClasses
optional parameter and set it totrue
. This will tell maven to create aPM-WebCommon-<version>-classes.jar
that you'll then be able to declare as dependency in PM-Client1 (with aprovided
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.您可以使用配置文件参见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
另请比较问题 不同 WAR 文件、共享资源 的答案。
Compare also the answers for question different WAR files, shared resources .