Search code examples
javamavenjarwarmaven-war-plugin

Maven war plugin archiveClasses but exclude a package


My maven project contains two src packages and several dependencies. I packaged it as a war and included al dependencies like libs in WEB-INF/libs.

Now I need to include inside a jar all compiled project classes from com.path.to.package.a, but I also need to exclude compiled classes contained in com.path.to.package.b.

I know I can use the <archiveClasses> option like:

<groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <archiveClasses>true</archiveClasses>
    </configuration>
</plugin>

This puts correctly the jar project inside the libs, but obviously it keeps all .class files.

I tried to perform the exclusion with some options like <packagingExcludes> or <warSourceExcludes>, but no luck with those.

Is there any option I can use paired with <archiveClasses> in order to exclude form the jar what i need?


Solution

  • Since it seams there isn't yet a solution like the one I was looking for, I ended up with the quick and dirty following one:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
            <execution>
                <id>delete-unused-classes</id>
                <phase>test</phase>
                <goals>
                    <goal>run</goal>
                </goals>
                <configuration>
                    <tasks>
                        <delete includeemptydirs="true">
                            <fileset dir="${project.build.outputDirectory}/com/path/to/pachage/a" />
                        </delete>
                    </tasks>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    Doing this way the unwanted classes are deleted before they are packaged from the <archiveClasses> and they do not appear inside the jar lib.