Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove my Test Classes from my ShrinkWrap Archive

How can I filter classes out of my final archive?

public static JavaArchive unitTestJar() {
    return ShrinkWrap.create( JavaArchive.class )
            .addAsManifestResource( EmptyAsset.INSTANCE, "beans.xml" )
            .addPackages( false, getCorePackages() );
}

public static String[] getCorePackages( String... args ) {
    List<String> strings = Arrays.asList(
            "com.lm.util",
            "com.lm.infrastructure"
    );

    strings.addAll( Arrays.asList( args ) );
    return (String[]) strings.toArray();
}

I see that there's a Filter API, but I can't seem to find any examples of how to use it. Ultimately I figured I'd just remove anything that is *Test*. Which is easier than trying to add a class at a time.

like image 388
xenoterracide Avatar asked Feb 17 '14 21:02

xenoterracide


1 Answers

Try this:

ShrinkWrap.create(WebArchive.class)  
          .addPackages(true, Filters.exclude(".*Test.class"), getCorePackages());
like image 91
Guy Bouallet Avatar answered Oct 14 '22 19:10

Guy Bouallet