基于maven概要激活上下文参数

基于maven概要激活上下文参数,maven,Maven,devI正在尝试使用maven配置文件设置上下文参数的值。 假设我在WEB-INF/WEB.xml中有以下布尔Ctx参数: 我在我的pom.xml中添加了以下插件 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration>

devI正在尝试使用maven配置文件设置上下文参数的值。 假设我在WEB-INF/WEB.xml中有以下布尔Ctx参数:

我在我的pom.xml中添加了以下插件

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
        <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>

org.apache.maven.plugins
maven战争插件
真的
真的
src/main/webapp
**/web.xml
src/main/webapp
src/main/webapp/WEB-INF/WEB.xml
我的个人资料特定的应用程序。属性通过此插件读取:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>read-project-properties</goal>
            </goals>
            <configuration>
                <files>
                    <file>${profile.resources}/application.properties</file>
                </files>
            </configuration>
        </execution>
    </executions>
</plugin>

org.codehaus.mojo
属性maven插件
初始化
读取项目属性
${profile.resources}/application.properties
其中,${profile.resources}在maven概要文件中定义:

 <profile>
    <id>dev</id>
    <properties>
        <env>integration</env>
        <profile.resources>src/main/config/dev</profile.resources>
    </properties>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
</profile>

发展
整合
src/main/config/dev
真的
我是基于类似的问题和很少的建议来做上述工作的,但到目前为止,没有任何效果。我不确定我在这里错过了什么?
(我使用的是maven v3.2.2)

我用你的配置做了一个简单的项目,我无法重现这个问题。我运行了
mvn clean install
,然后解压WAR,查看
web.xml
。它被正确过滤。@Tunaki-我确认它在war文件中。实际上,我是使用maven命令行运行应用程序的,不知怎么的,我期望上下文参数的运行时替换,但我没有意识到它是编译时静态替换。谢谢你向我指出这一点。如果你把它放在正确的“回答”中,我会接受一个答案。奇怪的是,使用maven命令(在jetty上)运行服务器时没有识别该插件?你运行了什么确切的maven命令?mvn clean install liquibase:update jetty:run
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>read-project-properties</goal>
            </goals>
            <configuration>
                <files>
                    <file>${profile.resources}/application.properties</file>
                </files>
            </configuration>
        </execution>
    </executions>
</plugin>
 <profile>
    <id>dev</id>
    <properties>
        <env>integration</env>
        <profile.resources>src/main/config/dev</profile.resources>
    </properties>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
</profile>