Java 将特定属性从资源复制到war';用Maven实现WEB-INF

Java 将特定属性从资源复制到war';用Maven实现WEB-INF,java,maven,properties,war,Java,Maven,Properties,War,我有一个Maven项目(运行在Tomcat10上的Java Web项目),它将被交付一场战争,并将分几个阶段部署。 因此,我为每个阶段定义了一些属性。它们位于 resources/config并具有以下文件: application-dev.properties application-prod.properties log4j2-dev.properties 为此,我希望Maven在构建war文件时只复制指定的文件 我在我的pom.xml中定义了一些构建概要文件,例如: <prof

我有一个Maven项目(运行在Tomcat10上的Java Web项目),它将被交付一场战争,并将分几个阶段部署。 因此,我为每个阶段定义了一些属性。它们位于

resources/config
并具有以下文件:

  • application-dev.properties
  • application-prod.properties
  • log4j2-dev.properties
为此,我希望Maven在构建war文件时只复制指定的文件 我在我的
pom.xml
中定义了一些
构建概要文件
,例如:

<profile>
        <id>dev</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <tasks>
                                    <delete dir="${project.build.finalName}/config/"/>
                                    <!-- Log4j Configuration -->
                                    <copy file="src/main/resources/config/log4j2-dev.properties"
                                          tofile="${project.build.finalName}/log4j2.properties"/>
                                    <!-- Application Properties -->
                                    <copy file="src/main/resources/config/application-dev.properties" tofile="${project.build.finalName}/config/application.properties"/>                                    </tasks>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
要通过Maven的WAR插件将指定的属性文件(根据构建概要文件中定义的任务)组装到WAR中,我需要做哪些更改

    <build>
    <finalName>${project.name}</finalName>
    <sourceDirectory>src/main/java</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webResources>
                    <resource>
                        <directory>src/main/webapp/META-INF</directory>
                        <filtering>true</filtering>
                        <targetPath>META-INF</targetPath>
                    </resource>
                    <resource>
                        <directory>src/main/webapp/WEB-INF</directory>
                        <filtering>true</filtering>
                        <targetPath>WEB-INF</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </plugin>