This turned out to be a Maven question much more than a Vaadin question. Still I'll answer the question in the context of Vaadin.
Recap: I want to maintain only one web.xml
. That should be the one in my -ui module as all source code generally reside there and really there should be no source code in the -production module.
Problem: The maven-war-plugin's overlay feature doesn't copy nor merge the web.xml from the overlay into the target.
I've solved it in a couple of steps. First I enhanced my web.xml in the -ui module with the following:
...
<context-param>
<description>Vaadin turn debugging mode on/off</description>
<param-name>productionMode</param-name>
<param-value>${vaadin.productionmode}</param-value>
</context-param>
...
Then in the pom.xml for the -ui module I added:
<properties>
...
<vaadin.productionmode>false</vaadin.productionmode>
</properties>
and in the pom.xml for the -production module I added:
<profiles>
<profile>
<id>production</id>
<properties>
<vaadin.productionmode>true</vaadin.productionmode>
</properties>
...
Now we have a Maven property, vaadin.productionmode
, which by default has a value of false, except if the production profile is active in which case the value is true. We've also prepared our web.xml
for Maven filtering. But we also need to activate the filtering (-ui module's POM):
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
...
<!-- Do filtering on web.xml -->
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
</configuration>
(The Maven WAR plugin doesn't do filtering on web.xml
file unless you set this config parameter)
You also need to activate web.xml filtering on the -production module's POM:
<profiles>
<profile>
<id>production</id>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
...
<configuration>
<!-- Do filtering on web.xml -->
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
<!-- Use web.xml from UI module -->
<webXml>../myapp-ui/src/main/webapp/WEB-INF/web.xml</webXml>
<overlays>
...
And finally as you can see in the XML above I've told the -production module that it should use the web.xml
from the -ui project. And that's the real trick! You can now remove the web.xml
file from the -production module as it's no longer used.
What has been accomplished:
- The web.xml's content has become variable using the Maven filtering feature. The variable
vaadin.productionmode
gets set differently when production profile is active in Maven.
- The -production module now no longer has its own web.xml. Instead it copies the file from the -ui module (doing proper filtering after copying).