Maven war plugin archiveClasses but exclude a package

Lorenzo Sciuto

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?

Lorenzo Sciuto

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

maven-war-plugin ignores <archiveClasses>

From Dev

How to exclude certain resources from the maven war plugin war file?

From Dev

Filtering in maven-war-plugin does not exclude directory

From Dev

maven-war-plugin: exclude all directories but one

From Dev

Filtering in maven-war-plugin does not exclude directory

From Dev

how to use maven bundle plugin to exclude package out of bundle

From Dev

How to use maven assembly plugin to exclude a package from dependency jar?

From Dev

maven exclude plugin in dependency

From Dev

Deploy war with Jetty maven plugin

From Dev

Maven war plugin not filtering as expected

From Dev

Maven - Exclude class files from war

From Dev

Conditionally exclude some resources in maven from war

From Dev

Maven - Exclude class files from war

From Dev

maven - how to exclude an entire module on from war

From Dev

SpotBugs Maven Plugin exclude a directory

From Dev

Maven war plugin copy arbitrary files

From Dev

Use Maven Replacer Plugin Before WAR is Packaged

From Dev

maven-war-plugin and the Spring JavaConfig

From Dev

maven-war-plugin not filtering on local

From Dev

using maven-war-plugin with Spring BOM

From Dev

Maven-war-plugin - remove files

From Dev

maven-war-plugin include subdirectories

From Dev

malformed pom error with maven war plugin

From Dev

How to filter applicationContext using maven war plugin

From Dev

Wildfly-Maven-Plugin only Ear and War

From Dev

maven war plugin put my resources in war root directory

From Dev

maven-war-plugin ignores user property war.warName

From Dev

maven-war-plugin does not change .war default directory

From Dev

Grails app package to war using maven

Related Related

HotTag

Archive