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?
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)