views:

648

answers:

3

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.

A: 

Hello,

You can use the TrueZIP Maven Plugin ( http://mojo.codehaus.org/truezip-maven-plugin/ ).

See examples in:

http://svn.codehaus.org/mojo/trunk/mojo/truezip-maven-plugin/src/it/

Alex
Thanks, but it looks like I could use that to remove the files from the WAR, which is good, but I would also like to have them excluded from the working webapp directory so a "run in place" would work as well.
kebernet
+1  A: 

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.

Rich Seller
The classes are compiled GWT client side classes that don't need to be on the server, but do need to be compiled into /target/classes so that the GWT compile, test, and hosted run works properly.
kebernet
They need to be on your path certainly, but can't you move them into a jar project and add that as a "provided" scope dependency to the war?
Rich Seller
I could, I am just hoping to not do that. It makes spinning up a hosted mode browser a multi-step process.
kebernet
@kebernet making it a nested project with the WAR and JARs built in different child projects doesn't make spin up that much harder. Slower, but not that more complicated.
sal
@Rich, the resource filtering isn't going to work for classes unless you modify the compile to put the code into X/WEB-INF/classes and then define X to be a resource folder. That would work, but you'll have to hold your nose from the code stink.
sal
@sal I was not suggesting it would work for classes. I recommended to move the classes to another project. I included the section on filtering resources for reference
Rich Seller
A: 

You might have luck with this, assuming you them in a package that you can define with an ant pattern

  <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
                <excludes>**/dontneed/*.class</excludes>
        </configuration>
  </plugin>
sal