0

I have src and src_backup directories that are identical except that I have created src_backup from src by renaming (cache busting purpose) all the .js and .css files in

src/main/webapp/resources directory.

I am using maven-war-plugin 2.4. I want the WAR file to include renamed files from

src_backup/main/webapp/resources

and exclude original files from

src/main/webapp/resources

I am able to include from src_backup but cannot exclude from src. What I end up getting is the WAR file containing both versions of files (original ones as well as renamed ones). I have read more than 5 different sources (such as stackoverflow) and tried more than 20 different ways to do so but it does not work.

        <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>

I have also tried to use resources tag in the build tag but did not work.

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

I am sure I am missing something. Any help would be deeply appreciated.

Karthik Ganesan
  • 4,142
  • 2
  • 26
  • 42

1 Answers1

0

You could change warSourceDirectory, see warSourceDirectory in war mojo. For instance:

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

See also my answer to rename files, and not use different directories: Renaming static files when building WAR file using Maven

Community
  • 1
  • 1
FBB
  • 1,414
  • 2
  • 17
  • 29