0

我有相同的srcsrc_backup目录,除了我通过重命名(缓存破坏目的)从 src 创建 src_backup 中的所有 .js 和 .css 文件

src/main/webapp/resources 目录。

我正在使用maven-war-plugin 2.4。我希望 WAR 文件包含重命名的文件

src_backup/main/webapp/resources

并从中排除原始文件

src/main/webapp/资源

我可以从 src_backup 中包含,但不能从 src 中排除。我最终得到的是包含两个文件版本(原始文件和重命名文件)的 WAR 文件。我已经阅读了超过 5 种不同的来源(例如 stackoverflow)并尝试了 20 多种不同的方法,但它不起作用。

        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <warName>targetWAR</warName>
                <warSourceExcludes>/${baseDir}/src/main/webapp/resources</warSourceExcludes>
                <webResources>
                    <resource>
                        <directory>src_backup/main/webapp/resources</directory>
                        <targetPath>resources</targetPath>
                    </resource>
                    <resource>
                        <directory>src_backup/main/webapp/WEB-INF/views</directory>
                        <targetPath>WEB-INF/views</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </plugin>

我也尝试在构建标签中使用资源标签,但没有奏效。

    <resources>
        <resource>
            <directory>src/main/webapp/resources</directory>
            <excludes>
                <exclude>*</exclude>
            </excludes>
        </resource>
    </resources>

我确定我错过了一些东西。任何帮助将不胜感激。

4

1 回答 1

0

您可以更改warSourceDirectory,请参阅war mojo 中的 warSourceDirectory。例如:

<plugin>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <warSourceDirectory>${basedir}/src_backup/main/webapp/resources</warSourceDirectory>
  </configuration>
</plugin>

另请参阅我对重命名文件和不使用不同目录的回答:Renaming static files when building WAR file using Maven

于 2015-03-06T14:38:42.477 回答