Java 在WAR打包之前使用Maven Replacer插件

Java 在WAR打包之前使用Maven Replacer插件,java,maven,Java,Maven,这是我的pom.xml: 我的问题是我必须修改我的web.xml。除了在构建war文件后进行的修改之外,一切都正常。您应该将replacer插件绑定到prepare package阶段,因为生命周期插件总是在特定阶段首先执行。这是正常的:maven-war插件有一个默认的default-war执行,它在绑定到包阶段的所有其他插件之前执行。直接的解决方案是将maven replacer插件绑定到prepare package阶段,并在其配置中使用prepare package 但我要强调的是,你做

这是我的pom.xml:


我的问题是我必须修改我的
web.xml
。除了在构建war文件后进行的修改之外,一切都正常。

您应该将replacer插件绑定到prepare package阶段,因为生命周期插件总是在特定阶段首先执行。

这是正常的:
maven-war插件
有一个默认的
default-war
执行,它在绑定到
阶段的所有其他插件之前执行。直接的解决方案是将
maven replacer插件
绑定到
prepare package
阶段,并在其配置中使用
prepare package

但我要强调的是,你做错了™. 用Maven术语来说,这里需要的是过滤
web.xml
。通过将maven-war插件配置为

<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
然后,您可以使用以下命令:

<configuration>
  <filters>
    <filter>src/main/filters/filter.properties</filter>
  </filters>
  <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
  <webResources>
    <resource>
      <directory>/path/to/other/files/to/filter</directory>
      <includes>
        <include>MessageResources.properties</include>
      </includes>
      <filtering>true</filtering>
      <targetPath>[...]</targetPath>
    </resource>
  </webResources>
</configuration>
最后用

<configuration>
  <filters>
    <filter>src/main/filters/filter.properties</filter>
    <filter>${filterFile}</filter>
  </filters>
  <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
</configuration>

src/main/filters/filter.properties
${filterFile}
真的

prepare package
中,我有一个错误:
[error]无法执行goal com.google.code.maven replacer插件:replacer:1.5.2:project apex上的replace(默认)文件'D:\workspace\with\target\Lyreco\u 2\u 50.3-0\u DEV\WEB-INF\WEB.xml'不存在->[Help 1]
当我查看我的目标文件夹时,目录
Lyreco_2_50.3-0_DEV
此时并未创建,只是查看了替换者正在做什么。我很确定这可以用maven war插件的过滤选项来代替,请看@RobertScholte是的,我只是回答了这个问题。但是在您的配置中,maven说如何更改web.xml?使用
prepare package
我有一个错误:
[error]无法在project apex:F文件'D:\workspace\with\target\Lyreco_2_50.3-0_DEV\WEB-INF\WEB.xml'上执行目标com.google.code.maven replacer插件:replacer:1.5.2:replace(默认值)
@Mercer已确认该插件可以进行更改。Maven将在构建时过滤文件,并自动替换令牌。我强烈建议您选择过滤路径@Mercer和您关于
web.xml
的错误不存在也是正常的。它真的不存在,也不应该存在。因为你做错了:)!好的,它适用于
web.xml
文件,您可以说
Maven将在构建时过滤文件,自动替换令牌
,但我有一个文件
MessageResources.properties
,具有相同的令牌,但它不会替换
<configuration>
  <filters>
    <filter>src/main/filters/filter.properties</filter>
  </filters>
  <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
  <webResources>
    <resource>
      <directory>/path/to/other/files/to/filter</directory>
      <includes>
        <include>MessageResources.properties</include>
      </includes>
      <filtering>true</filtering>
      <targetPath>[...]</targetPath>
    </resource>
  </webResources>
</configuration>
<profile>
  <id>[...]</id>
  <!-- rest of configuration untouched -->
  <properties>
    <filterFile>src/main/filters/filter-[...].properties</filterFile>
  </properties>
</profile>
<configuration>
  <filters>
    <filter>src/main/filters/filter.properties</filter>
    <filter>${filterFile}</filter>
  </filters>
  <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
</configuration>