java - 将 Maven 文件过滤到 WEB-INF

标签 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>

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

我怎样才能把这个文件放到正确的地方。

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

最佳答案

<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>

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

如果有不清楚的地方更新。

关于java - 将 Maven 文件过滤到 WEB-INF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1782352/

相关文章:

java - 在 Spring Boot 中通过 JPA 正确利用纪元秒

java - 追加到现有文件而不覆盖它

java - 从 Maven 目标执行文件

java - 在 Maven 项目中重用常量和属性?

java - 如何使用 Java 在 Twilio 中使用 TwiML 而不是 URL 进行出站调用?

java - while 循环中的 StringIndexOutOfBoundsException

maven-2 - 如何在 IDE 中使用 Grails 依赖项

eclipse - Eclipse 中的多模块 Maven 项目

java - Spring 启动 Controller 404

java - 努力设置 pom.xml 文件。不断收到 Maven 强制执行器规则 2 错误