【问题标题】:How to set display-name in maven-war-plugin for web.xml如何在 maven-war-plugin 中为 web.xml 设置显示名称
【发布时间】:2012-05-08 12:55:16
【问题描述】:

如何使用 maven-war-plugin 通过 maven 定义 web.xml 显示名称?

在 maven-ear-plugin 中有一个配置选项 displayName 来设置 EAR / application.xml display-name 属性。

错误的方法?直接在web.xml中手动设置?

【问题讨论】:

    标签: maven web.xml maven-war-plugin


    【解决方案1】:

    您需要使用 Maven 的 web resource filtering 方法。在您的 maven-war-plugin 中设置以下配置:

    <plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <webResources>
            <resource>
                <directory>src/main/webapp/WEB-INF/</directory>
                <targetPath>WEB-INF</targetPath>
                <includes><include>web.xml</include></includes>
                <filtering>true</filtering>
            </resource>
        </webResources>
    </configuration>
    </plugin>
    

    在您的 web.xml 中,您可以使用 pom.xml 中定义的任何属性。所以你可以例如使用:

    <display-name>${project.name} - ${project.version}</display-name>
    

    这将被呈现为

    <display-name>My Awesome Webapp - 1.0.0-SNAPSHOT</display-name>
    

    如果您使用 Eclipse,则需要m2e-wtp(查看主页中的网络资源过滤截屏视频)

    【讨论】:

      【解决方案2】:

      更简单...

      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
        </configuration>
      </plugin>
      

      请参阅filteringDeploymentDescriptors 的文档。这从 2.1 开始可用,但默认情况下被禁用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-10-13
        • 1970-01-01
        • 1970-01-01
        • 2012-03-03
        • 2017-08-25
        • 2015-11-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多