Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use different web.xml descriptor in tomcat7-maven-plugin:run?

I would like to have two different web.xml descriptor files in my maven project. First (default) should be included in war file for deployment to application server and second should be used for development using tomcat7-maven-plugin:run. I know there is <tomcatWebXml> parameter but it specifies Tomcat global web.xml which I don't want to change.

For jetty-maven-plugin:run I can specify either <webApp>/<descriptor> or <webApp>/<overrideDescriptor>. First replaces default web.xml with specified file while second applies specified file content in addition to default web.xml.

Is there some possibility how to achieve same functionality with tomcat7-maven-plugin?

like image 765
Vojta Avatar asked Nov 02 '22 14:11

Vojta


1 Answers

It is an old question, but I will write this here in case anyone else is looking.

Yes, it is possible.

You can do this by overriding the default (built-in) war-builder that tomcat7-maven-plugin uses, which is org.apache.maven.plugins:maven-war-plugin The override is done by simply adding that plugin to your pom.xml, along with the extra configuration webXml

The code will look like this

    <plugins>
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <webXml>myPath/web.xml</webXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                ... other configurations here
            </configuration>
        </plugin>
        ...
    </plugins>
like image 172
Robin Sving Avatar answered Nov 09 '22 10:11

Robin Sving