Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering web.xml when using the jetty-maven-plugin?

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?

like image 600
Sebastian S. Avatar asked Jun 18 '13 12:06

Sebastian S.


1 Answers

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

like image 178
Sebastian S. Avatar answered Sep 28 '22 05:09

Sebastian S.