Search code examples
javamavenwarmaven-pluginmaven-war-plugin

Maven WAR plugin - change front-end resources location


After minification I have content of webapp like this:

WEB-INF
assets
favicon
i18n
scripts
dist
index.html
//other things

Where inside dist I have compressed styles, scripts etc... But Maven WAR plugin copies everything to WAR, which causes WAR contains unminificated sources. I tried to change directory for webResources:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>${maven-war-plugin.version}</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
         packagingExcludes>WEB-INF/lib/tomcat-*.jar</packagingExcludes>
         <webResources>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/webapp/dist</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </webResources>
    </configuration>
</plugin>

But nothing changed. Can anyone help me with this? Thank you in advance for every answer.


Solution

  • packagingExcludes accepts a comma separated list of resources not to include. Add all the directories to it, that you want excluded, e.g.

    <packagingExcludes>
        WEB-INF/lib/tomcat-*.jar,
        scripts
    </packagingExcludes>
    

    You also need to make sure that resources are not included by the maven resources plugin.

    Instead of manually dealing with all the exclusions, I recommend to move all the files, that you don't want to end up in your war file, out of the directories, maven expects to contain the resources by default. You could move them to e.g. src/main/uncompressedResources. That way they'd still be in the project, but maven would not include them by default.