开发者

Maven - several modules for one package

I have a web app that I would like to split into three pieces. I noticed it has two completely distinct functionalities, but the core architecture (libs used in presentation layer, Spring container, DAO etc.) is shared.开发者_开发知识库

One piece would be the "master", with full vertical stack from presentation through DAO, but only for what's common for all "subprojects".

The other two modules would be the "subprojects" themselves.

Now the question is: Is it possible to get Maven to treat all 3 pieces (modules?) as one, so that they would be built and most importantly packaged together? I need the final result to be a single war with directory tree similar to:

war
 + WEB-INF
   + classes
     + subproject1
     + subproject2
 + view-shared
   + css
     + ...
   + js
     + ...
 + subproject1
   + myPage.jsp
 + subproject2
   + anotherPage.jsp

You get the idea.


You can do it using the Maven assembly plugin.

Another solution is to have:

  • A common project (packaging jar)
  • A subproject1 (packaging war) that has common as dependency.
  • A subproject2 (packaging war) that has common as dependency.
  • Finally, a web project (packaging war) that has both subproject1 and subproject2 as dependencies.

When Maven will build the web project, it will first unzip both subproject1 and subproject2 wars in the web/target directory, and then copy the content of the web project itself in this target directory.

This means that if a file exists in subproject1 and in web projects, then the file hosted by web will erase the one hosted by subproject1 in the final WAR file.

You can find more information about Maven WAR overlays.


Yes, you can do that with the maven assembly plugin. Build separate maven modules for all three, plus a forth module that depends on the other modules and uses the assembly plugin to build the structure you need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜