简体   繁体   中英

Maven Exclude Files During Build

I am having problems getting Maven to build my webapp without including extraneous development file, such as unminified script and css files.

First i tried using exclude in combination with webResources

<build>     
    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <warName>ReportRocket-1</warName>
                <webResources>
                    <resource>
                        <directory>src/main/webapp/resources/</directory>
                        <excludes>
                            <exclude>annotated-js/*.js</exclude>
                            <exclude>compiled-js/*.js</exclude>
                            <exclude>css/*.css</exclude>
                            <exclude>less/*.less/exclude>
                        </excludes>
                        <directory>src/main/webapp/WEB-INF</directory>
                        <excludes>
                            <exclude>connection.json</exclude>
                            <exclude>reportRocket.jsp</exclude>
                        </excludes>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
    </plugins>
</build>

The result was the contents of WEB-INF being duplicated in the project root and no excluded directories or files.

So, I looked around here and found this: maven2: excluding directory from WAR but running mvn clean package using either warSourceExcludes or packagingExcludes results in the directories i'm trying to exclude not being, well, excluded...

The build section of my pom.xml

<build>     
    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <warName>ReportRocket-1</warName>
                <packagingExcludes>
                    src/main/webapp/resources/annotated-js/,
                    src/main/webapp/resources/compiled-js/,
                    src/main/webapp/resources/css/,
                    src/main/webapp/resources/less/,
                    src/main/webapp/WEB-INF/connection.json
                </packagingExcludes>
            </configuration>
        </plugin>
    </plugins>
</build>

Building the project with these settings results in the following project structure:

META-INF
resources
    //desired folders
    annotated-js
    compiled-js
    css
    less
WEB-INF
    // desired files
    connection.json

This is my first time using a build tool, so i'm probably overlooking something simple but in the meantime, this is driving me crazy. Any suggestions or obvious problems with my xml?

First you should read the documentation of the maven-war-plugin cause the packagingExclude is intended for a different purpose, but in your case you need to do the configuration in that way :

<configuration>
  <webResources>
    <resource>
      <!-- this is relative to the pom.xml directory -->
      <directory>src/main/webapp/resources/</directory>
      <!-- there's no default value for this -->
      <excludes>
        <exclude>annotated-js/**</exclude>
      </excludes>
    </resource>
  </webResources>
</configuration>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM