5

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?

Vojta
  • 1,583
  • 17
  • 19
  • Could you elaborate why `tomcatWebXml` is no good for you? – Sander Verhagen Sep 27 '13 at 05:27
  • Parameter `` overrides Tomcat global web.xml file. In fact I want to use the original file which is released as part of Tomcat. And I also don't want to copy&paste this 150KB long file to my `web.xml` file. – Vojta Oct 07 '13 at 12:08

1 Answers1

2

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>
Robin Sving
  • 1,902
  • 1
  • 12
  • 10
  • Good idea but I needed two web.xml files, default for deployment to application server and second for tomcat. This could be done by moving your maven-war-plugin configuration to maven profile. But then developers would have to specify this profile each time they run tomcat. – Vojta Sep 22 '15 at 12:56