【问题标题】:replacing file into WAR file which is generated by mvn package将文件替换为由 mvn 包生成的 WAR 文件
【发布时间】:2020-04-06 12:10:22
【问题描述】:

我有一个 maven 项目,我想在使用 clear package maven 命令时从源代码替换配置文件,并将其替换为 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>

【问题讨论】:

  • 请详细说明您喜欢做什么以及为什么需要做什么?因为我不明白你的问题..
  • 让我们假设我有一个名为 A..css 的文件,这个文件在我的资源中。生成 WAR 文件时,我需要将此文件替换为另一个名为 B.css 的文件,我如何在 pom.xml 中执行此操作?
  • 为什么项目中没有B.css而不是A.css
  • 因为在创建战争文件时,我需要特定风格的战争而不是我的本地风格
  • 所以你真正的问题是:你想要一个用于本地构建的 CSS 和一个用于官方构建的 CSS?

标签: java maven pom.xml


【解决方案1】:

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

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>

【讨论】:

    猜你喜欢
    • 2012-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-26
    • 1970-01-01
    • 2011-09-04
    • 1970-01-01
    • 2017-11-02
    相关资源
    最近更新 更多