【发布时间】:2016-03-22 16:01:23
【问题描述】:
我的 Maven 应用有 3 个不同的配置文件,如下所示
<profiles>
<profile>
<id>dev</id>
<properties>
<profileVersion>DEV</profileVersion>
<webXmlFolder>${id}</webXmlFolder>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<profileVersion>1.0.0-RC1</profileVersion>
<webXmlFolder>${id}</webXmlFolder>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profileVersion>1.0.0-Final</profileVersion>
<webXmlFolder>${id}</webXmlFolder>
</properties>
</profile>
</profiles>
我有这样的 Maven 结构:
src/main/config/default/WEB-INF/web.xml
src/main/config/dev/WEB-INF/web.xml
src/main/config/test/WEB-INF/web.xml
src/main/config/prod/WEB-INF/web.xml
src/main/webapp/WEB-INF/
我的任务是在构建时将指定的 web.xml 设置为 webapp/WEB-INF,这取决于指定的配置文件。如果未指定配置文件,则 web.xml 将从默认文件夹复制。
我有插件,但它不工作。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-prod-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<outputDirectory>${project.build.outputDirectory}/classes/WEB-INF</outputDirectory>
<resources>
<resource>
<directory>src/main/config/${webXmlfolder}/WEB-INF</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
有什么想法吗?我花了很多时间来解决这个问题,现在我有点困惑。
【问题讨论】:
-
所有定义的配置文件都依赖于 ${id} 属性,它是否在 POM 的其余部分中定义?
-
我的错误是 ${id} 占位符值是定义的应用程序的全名,例如 [groupId:artifactId:version] 而不是配置文件 ID 名称。 :)