将Maven文件过滤到WEB-INF中

Xet*_*ius 44 java maven-2 pom.xml

我试图添加一些过滤到应用程序上下文文件,该文件驻留在WEB-INF目录中.

我在文件夹/ src/main/resources中有要过滤的文件(xmlgateway-context.xml).

我在文件夹src/main/filters中有属性文件(config-e05.properties)

我的POM设置如下:

<!-- environment profiles -->
<profiles>
 <profile>
  <id>e04</id>
  <properties>
   <targetenv>e04</targetenv>
  </properties>
 </profile>
 <profile>
  <id>e05</id>
  <properties>
   <targetenv>e05</targetenv>
  </properties>
 </profile>
</profiles>

<!-- build settings (filtering) -->
<build>
 <filters>
  <filter>src/main/filters/config-${targetenv}.properties</filter>
 </filters>
 <resources>
  <resource>
   <targetPath>WEB-INF</targetPath>
   <filtering>true</filtering>
   <directory>src/main/resources</directory>
  </resource>
 </resources>
</build>
Run Code Online (Sandbox Code Playgroud)

这将正确安装mvn,但是当我打开输出war文件时,我希望文件xmlgateway-context.xml位于/ WEB-INF目录中,但它最终位于/ WEB-INF/classes/WEB文件夹中-INF.

如何将此文件放到正确的位置.

或者,我可以将应用程序上下文放在不同的位置并在那里引用它.

pea*_*kit 90

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
            <webResources>
                <resource>
                    <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                    <filtering>true</filtering>
                    <targetPath>WEB-INF</targetPath>
                    <includes>
                        <include>**/xmlgateway-context.xml</include>
                     </includes>
                </resource>
            </webResources>
        </configuration>
    </plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)

将上面的内容添加到您的pom.xml中. 编辑:只是解释上面的conf正在做什么.添加了这个,mvn将过滤文件src/main/webapp/WEB-INF,特别是过滤包含的文件xmlgateway-context.xml,过滤后它将推送文件WEB-INF夹中的文件(这就是target标签所说的).

如果不清楚,请更新.

  • 只是一个观察添加,版本2.4似乎不适用于此配置,最近和使用此设置我发现是2.3,欢呼. (5认同)

dfa*_*dfa 5

您应该通过maven war 插件配置过滤:查看这些示例

  • 如果我能感谢链接,我也会接受这一点,但由于我的剪切和粘贴懒惰,@peakit 获胜。 (4认同)