【发布时间】:2014-04-09 18:09:32
【问题描述】:
我正在尝试使用 Maven 在开发和生产中的 web.xml 文件中引入不同的配置点。看起来使用配置文件和过滤器是可行的方法,当我使用“mvn install”或“mvn package”构建 WAR 文件时,这确实有效。但是,通过 Tomcat 7 插件运行它总是会导致“无法解析占位符”错误。以下是相关行:
在 web.xml - 这是我要设置的占位符
/WEB-INF/${sec-file-path}
在 pom.xml 中
<profiles>
<profile>
<id>development</id>
<properties>
<sec-file-path>one-thing-for-dev.xml</sec-file-path>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<sec-file-path>one-thing-for-prod.xml</sec-file-path>
</properties>
</profile>
</profiles>
....
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<artifactId> maven-war-plugin </artifactId>
<version>2.4</version>
<configuration>
<webResources>
<resource>
<filtering>true</filtering>
<directory>src/main/webapp</directory>
<includes>
<include>**/web.xml</include>
</includes>
</resource>
</webResources>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
运行命令“mvn package -P development”按预期工作并适当地填充占位符。但是,运行“mvn tomcat7:run -P development”会导致“无法解析占位符”错误。欢迎大家提出意见。
【问题讨论】: