Original Post:
I want to filter the web.xml
deployment descriptor of a Java 6 web application which is running on the Jetty 8.1 servlet container, but it does not work so far. I want to set a different JSF project stage depending on the active maven profile:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>${jsfProjectStage}</param-value>
</context-param>
The profiles section in the pom.xml
looks like that:
<profiles>
<profile>
<id>development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<jsfProjectStage>Development</jsfProjectStage>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<jsfProjectStage>Production</jsfProjectStage>
</properties>
</profile>
</profiles>
On the internet you find several ways to accomplish that, e.g. using alternative web.xml files. But to me the most obvious way seems to use the maven-war-plugin:
<build>
<finalName>...</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<webResources>
<webResource>
<directory>src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
<includes>
<include>web.xml</include>
</includes>
</webResource>
</webResources>
</configuration>
</plugin>
...
</plugins>
</build>
Since you find many answers or articles with this code snippet, I wonder why it is not working for me. I tried to replace <webResource>
with <resource>
(often found it this way) and I also tried to add <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
but nothing of that works.
Does anyone have an idea, what is missing here in order to filter the web.xml correctly? Or do I have to explicitly specify <filters>
?
Thanks
Sebastian
Update:
Thanks to user944849 I know now that the reason for my not filtered web.xml
is not the maven-war-plugin but the jetty-maven-plugin, since I use mvn jetty:run
to run the (unassembled) webapp. Does anyone know how to bring the jetty-maven-plugin to filter the web.xml
before running the unassembled webapp?
After figuring out that the problem was not the maven-war-plugin but the jetty-maven-plugin, I just had to change the maven command from mvn clean jetty:run
to mvn clean jetty:run-war
in order to run an assembled webapp on the embedded jetty in which the deployment descriptor gets also filtered.
Thanks for your help guys
Sebastian
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With