首页 > 解决方案 > 将文件替换为由 mvn 包生成的 WAR 文件

问题描述

我有一个 maven 项目,我想在使用clear packagemaven 命令时从源代码替换配置文件并将其替换为 WAR 中令人兴奋的一个。我试过了,但替换只发生在提取的文件夹而不是 WAR 文件中,这是我的 pom.xml

            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.2</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <overwrite>true</overwrite>
                            <outputDirectory>target/Project-xyz/classes/resources</outputDirectory>  
                            <resources>
                                <resource>
                                    <directory>${basedir}/src/main/java/resources/customers</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

标签: javamavenpom.xml

解决方案


经过这么多试验,它通过使用

org.apache.maven.plugins

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <executions>
        <execution>
            <id>default-war</id>
            <configuration>
                <webResources>
                    <resource>
                        <directory>src/main/webapp/resources/customer1/css</directory>
                        <targetPath>resources/css</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </execution>
    </executions>
</plugin>

推荐阅读