How do you copy one of two web.xml files into the WEB-INF folder based on a profile?

0 votes
asked Sep 12, 2017 by user3926339

I'm attempting to build a war with one of two different web.xml files based on the build profile. I thought it would work if I used the resource tag but it's putting the web.xml file into the target/WEB-INF/classes directory and I need it in the target/WEB-INF directory. Here's a snippet of my pom:

    <profile>
        <id>war_ssl</id>
        <modules>
            <module>ess-spring</module>
        </modules>
        <build>
            <resources>
                <resource>
                    <directory>${basedir}/src/main/resources</directory>
                </resource>
                <resource>
                    <directory>${basedir}/src/main/web_xml/ssl</directory>
                </resource>
            </resources>
        </build>
    </profile>
    <profile>
        <id>war_no_ssl</id>
        <modules>
            <module>ess-spring</module>
        </modules>
        <build>
            <resources>
                <resource>
                    <directory>${basedir}/src/main/resources</directory>
                </resource>
                <resource>
                    <directory>${basedir}/src/main/web_xml/no_ssl</directory>
                </resource>
            </resources>
        </build>
    </profile>

Note that there is only one file in each dir, ${basedir}/src/main/web_xml/ssl and ${basedir}/src/main/web_xml/no_ssl and that's a different version of web.xml.

Very specifically, I want all resources with the exception of one file (web.xml) in both profiles and just one of the specific web.xml files depending on the selected profile. And I can't figure out how to tell it to write the web.xml file into the WEB-INF directory. It's going into the WEB-INF/classes directory. Please let me know if what I want to do is even possible in Maven (and how to do it if it is).

================================================

It turns out that Wemu's suggestion below did \what I wanted. Here is the revised, snippet:

    <profile>
        <id>war_ssl</id>
        <modules>
            <module>ess-spring</module>
        </modules>
        <build>
             <plugins>
                 <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.1.0</version>
                    <configuration>
                        <webXml>${basedir}/src/main/web_xml/ssl/web.xml</webXml>
                    </configuration>
                </plugin>
            </plugins> 
        </build>
    </profile>
    <profile>
        <id>war_no_ssl</id>
        <modules>
            <module>ess-spring</module>
        </modules>
        <build>
             <plugins>
                 <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.1.0</version>
                    <configuration>
                        <webXml>${basedir}/src/main/web_xml/no_ssl/web.xml</webXml>
                    </configuration>
                </plugin>
            </plugins> 
        </build>
    </profile>

The war.xml file is in the correct place now. Thanks Wemu!!!

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...