Jua*_*ero 23 eclipse eclipse-wtp maven m2e
我正在尝试使用Maven过滤过滤Spring配置文件.我的POM配置如下:
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webResources>
<resource>
<filtering>true</filtering>
<targetPath>WEB-INF/context</targetPath>
<directory>src/main/webapp/WEB-INF/context</directory>
<includes>
<include>applicationContext.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
...
Run Code Online (Sandbox Code Playgroud)
和
<profiles>
<profile>
<id>desarrollo</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<filters>
<filter>src/main/properties/dev.properties</filter>
</filters>
</build>
</profile>
<profile>
<id>pruebas</id>
<build>
<filters>
<filter>src/main/properties/test.properties</filter>
</filters>
</build>
</profile>
...
Run Code Online (Sandbox Code Playgroud)
它直接调用Maven时效果很好.
不幸的是,当使用Eclipse WTP和m2e在Tomcat 6中热部署webapp时,它总是选择未经过滤的applicationContext.xml版本.(文件夹target/m2e-wtp/web-resources/WEB-INF/context中的文件applicationContext.xml永远不会被过滤)
我找不到有关该主题的任何有用文档.我甚至不确定它是否在m2e中实现.
我的配置有问题,或者这是一个未实现的功能?
Jua*_*ero 26
好吧,最后我明白了.
首先,我做了khmarbaise所指出的.我将applicationContext.xml移动到resources文件夹.War插件webResources用于处理外部资源,并且过滤目标文件夹本身的文件不是最佳做法.我更新了POM以反映新配置
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
Run Code Online (Sandbox Code Playgroud)
和
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webResources>
<resource>
<filtering>true</filtering>
<targetPath>WEB-INF/context</targetPath>
<directory>src/main/resources/WEB-INF/context</directory>
<includes>
<include>applicationContext.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
所以,他的一半功劳.但这还不够,它仍然没有奏效.我意识到Maven/m2e确实正在过滤我的文件,但它没有得到我定义的属性文件.经过一些测试后,我发现m2e忽略activeByDefault了配置文件激活部分中的选项.
所以,我将我的默认配置文件添加到项目Maven配置中然后它工作了

小智 9
我在过滤web.xml时遇到了类似的问题.我通过在eclipse中重新导入整个项目来解决问题.
原因是损坏的/.settings/org.eclipse.wst.common.component文件.在此文件中,定义了复制到本地Web服务器部署目录的文件的顺序.例如:
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="liquidvote-rest">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="context-root" value="myapp"/>
<property name="java-output-path" value="/myapp/target/classes"/>
</wb-module>
</project-modules>
Run Code Online (Sandbox Code Playgroud)
如果web.xml或application.xml存在于多个目录中,则将从找到的第一个目录中获取.因此重要的是
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
Run Code Online (Sandbox Code Playgroud)
是第一个条目.
您可以在http://wiki.eclipse.org/M2E-WTP_FAQ的"这个Web资源文件夹是什么?"部分找到更多信息.
| 归档时间: |
|
| 查看次数: |
35047 次 |
| 最近记录: |