Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude classes from a packaged webapp with maven

How can I filter certain classes in /target/classes from going into /target/[webapp]/WEB-INF/classes? I want them compiled into /target/classes/ but not in the final war.

like image 342
kebernet Avatar asked Aug 20 '09 12:08

kebernet


1 Answers

What are these classes for? If they are for testing, you can specify them in src/test/java, they will then be compiled into target/test-classes in the test-compile phase, but won't be included in the final war.

If they aren't for testing and aren't to be included in the war, perhaps they should be refactored into another project so you can specify it as a dependency (perhaps with "provided" scope so they won't be deployed.

For reference you can configure the war to include and exclude resources when packaging.

The following example will include all jpgs but exclude resources from the image2 sub folder:

    <configuration>
      <webResources>
        <resource>
          <!-- this is relative to the pom.xml directory -->
          <directory>resource2</directory>
          <!-- the list has a default value of ** -->
          <includes>
            <include>**/*.jpg</include>
          <includes>
          <excludes>
            <exclude>**/image2</exclude>
          </excludes>
        </resource>
      </webResources>
    </configuration>

See the war plugin documentation for more details.

like image 141
Rich Seller Avatar answered Nov 04 '22 02:11

Rich Seller