将Maven文件过滤到WEB-INF中 [英] Filtering Maven files into WEB-INF

查看:560
本文介绍了将Maven文件过滤到WEB-INF中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向应用程序上下文文件添加一些过滤,该文件位于WEB-INF目录中。

I am trying to add some filtering to the application context file, which resides in the WEB-INF directory.

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

I have the file which is to be filtered (xmlgateway-context.xml) in the folder /src/main/resources.

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

I have the properties files (config-e05.properties) in the folder src/main/filters

我将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 / classes / WEB-INF文件夹中。

This will mvn install correctly, but when I open the output war file, I was expecting the file xmlgateway-context.xml to be in the /WEB-INF directory, but it ends up in the folder /WEB-INF/classes/WEB-INF.

我该怎么办?将此文件放到正确的位置。

How can I get this file into the right place.

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

Alternatively, can I put the application context into a different location and have it referenced there.

推荐答案

<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中。
编辑:只是为了解释上述内容正在做什么。添加此内容后,mvn将过滤 src / main / webapp / WEB-INF 下的文件,特别是过滤包含的文件 xmlgateway-context。 xml 并在过滤后将推送 WEB-INF 文件夹中的文件(这就是 target 标签说。)

Add the above to your pom.xml. Just to explain what the above conf is doing. With this added, mvn is going to filter files under src/main/webapp/WEB-INF and in particular filter the included files xmlgateway-context.xml and after filtering it is going to push the files in WEB-INF folder (thats what the target tag is saying).

如果不清楚,请更新。

这篇关于将Maven文件过滤到WEB-INF中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆