tags:

views:

41

answers:

2

I'm deploying a web application to a service which requires me to package some of the classes to a Jar file.

So in example having the following source tree:

com.enterprise
   |------ package1
   |------ package2
   |------ package3

How can I create a jar including only classes from package1 and package3 but not package2?

+1  A: 

You can configure the Maven jar plugin with the maven.jar.excludes property that contains a list of what paths don't get included into the jar file. To my knowledge this property is automatically used when invoking mvn jar:jar.

Or you can directly configure the plugin to include/exclude paths:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    ...
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>jar</goal>
        </goals>
        <configuration>
          <classifier>client</classifier>
          <excludes>
            <exclude>**/service/*</exclude>
          </excludes>
        </configuration>
      </execution>
    </executions>
  </plugin>
Johannes Wachter
That did the trick.
escanda
Might be easier to specify just the files you want to include rather than the ones you want to exclude http://maven.apache.org/plugins/maven-jar-plugin/jar-mojo.html#includes
matt b
@matt that always depends on how complex the real structure is. I'm normally in favor of blacklisting small amounts than listing everything _but_ the ones to leave out.
Johannes Wachter
+1  A: 

Configure the jar plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <excludes>
            <exclude>com/yourcompany/package2/*</exclude>
        </excludes>
    </configuration>
</plugin>

You probably want to do this inside a profile

seanizer