如何使用Jenkins Build Paremeter编辑web.xml

时间:2019-04-11 11:05:51

标签: xml maven jenkins

我想基于Jenkins Build Paraemter在我的web.xml文件中编辑一些配置。

这是我在詹金斯(Jenkins)的建造目标:

clean compile war:war -Dparameter=$PARAMETER

这是我的web.xml文件:

...
<env-entry> 
    <env-entry-name>parameter</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>${parameter}</env-entry-value> 
</env-entry>
...

这可能吗?还是应该使用其他方式?

我是Maven项目的新手。

1 个答案:

答案 0 :(得分:0)

您必须为包含要过滤资源的每个资源文件夹激活filtering (which is in fact string/variable interpolation) on the Maven Resources Plugin

  <build>
    ...
    <resources>
      <resource>
        <directory>src/main/resources</directory>  <!-- re-define the default since an explicit
                                                        <resources> declaration overwrites it -->
      </resource>
      <resource>
        <directory>src/main/webapp/WEB-INF</directory>  <!-- contains web.xml, for example -->
        <filtering>true</filtering>
      </resource>
      ...
    </resources>
    ...
  </build>

顺便说一句,顺便说一句,您不必也不应在命令行上明确调用Maven WAR Pluginwar目标,因为:

  

war:war是在package阶段为包装类型为war的项目调用的默认目标。它会生成一个WAR文件。

mvn clean package ...实现了相同的目的(并且是Maven Build Lifecycle的预期用法)。