如何在 tomcat7-maven-plugin:run 中使用不同的 web.xml 描述符?

Voj*_*jta 5 tomcat maven maven-tomcat-plugin embedded-tomcat-7

我想要两个不同的 web.xml在我的 Maven 项目中描述符文件。第一个(默认)应该包含在用于部署到应用服务器的 war 文件中,第二个应该用于使用tomcat7-maven-plugin:run. 我知道有<tomcatWebXml>参数,但它指定了web.xml我不想更改的Tomcat 全局变量。

因为jetty-maven-plugin:run我可以指定<webApp>/<descriptor><webApp>/<overrideDescriptor>。Firstweb.xml用指定的文件替换 default ,而 second 除了 default 之外还应用指定的文件内容web.xml

有没有可能如何实现相同的功能tomcat7-maven-plugin

Rob*_*ing 2

这是一个老问题,但我会在这里写下,以防其他人正在寻找。

对的,这是可能的。

您可以通过覆盖 tomcat7-maven-plugin 使用的默认(内置)war-builder 来完成此操作,即 org.apache.maven.plugins:maven-war-plugin ,只需将该插件添加到您的pom.xml,以及额外的配置webXml

代码如下所示

    <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>
Run Code Online (Sandbox Code Playgroud)