Building different maven artifacts for different containers

怎甘沉沦 提交于 2019-12-11 08:26:11

问题


I want to create a project (multimodule) that runs both on Tomcat and on a full Java EE server. Since tomcat is missing a couple of libraries for that I need to include them for Tomcat, but a full Java EE container has these libraries and might even produce a conflict if I include them anyways.

I want to have all my html files in one place (probably the Java EE container WAR project) and then have another module that builds the same war, but with the added dependencies in the WAR-file.

How do I achieve this?


回答1:


You can use WAR overlays for this. With this approach, you can have one WAR module with all the shared stuff - libs, resources, etc. Then you create another module (or more of them, say for each container) and add a dependency of type WAR - like this:

<dependency>
    <groupId>com.example.app</groupId>
    <artifactId>my-war-base</artifact>
    <version>1-SNAPSHOT</version>
    <type>war</type>
</dependency>

Just adding this (to a WAR project!) ensures that the WARs are merged (=overlaid). You can even exclude some parts from the base war, for instance if you have some resources/libs required by many containers but problematic in single one.

Some more tweaks are possible - see the docs.

By the way, this approach allows you:

  • to build for all containers at once
  • to have consistent build outputs (same war => same purpose)


来源:https://stackoverflow.com/questions/13193385/building-different-maven-artifacts-for-different-containers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!