我正在尝试向位于 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/