【问题标题】:How to use different web.xml descriptor in tomcat7-maven-plugin:run?如何在 tomcat7-maven-plugin:run 中使用不同的 web.xml 描述符?
【发布时间】:2013-10-02 03:28:48
【问题描述】:

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

对于jetty-maven-plugin:run,我可以指定<webApp>/<descriptor><webApp>/<overrideDescriptor>。首先用指定的文件替换默认的web.xml,然后在默认的web.xml之外应用指定的文件内容。

是否有可能如何使用tomcat7-maven-plugin 实现相同的功能?

【问题讨论】:

  • 您能否详细说明为什么tomcatWebXml 对您不利?
  • 参数 <tomcatWebXml> 覆盖 Tomcat 全局 web.xml 文件。事实上,我想使用作为 Tomcat 的一部分发布的原始文件。而且我也不想将这个 150KB 长的文件复制并粘贴到我的 web.xml 文件中。

标签: maven tomcat maven-tomcat-plugin embedded-tomcat-7


【解决方案1】:

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

是的,有可能。

您可以通过覆盖 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>

【讨论】:

  • 好主意,但我需要两个 web.xml 文件,默认部署到应用程序服务器,第二个部署到 tomcat。这可以通过将您的 maven-war-plugin 配置移动到 maven 配置文件来完成。但是,开发人员每次运行 tomcat 时都必须指定此配置文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-04-04
  • 1970-01-01
  • 2011-04-29
  • 1970-01-01
  • 1970-01-01
  • 2013-09-30
  • 2010-12-02
相关资源
最近更新 更多