2 Replies Latest reply: Oct 16, 2010 4:45 AM by Aslak Knutsen RSS

UberJar archive type

Dan Allen Master

I thought of another useful container type for ShrinkWrap. So far the only nested Java archives we've created have been Java EE standard archives. Another common archive packaging is the UberJar (or as Maven calls it, a shaded JAR). An UberJar is a JAR containing other JAR files. What makes it unique, though, is that when it's exported, those jars are flatted into a single non-nested JAR.

 

I'm thinking we call this archive a UberJavaArchive or ShadedJavaArchive. It would be a LibraryContainer only, but somehow we need to weave in this merging export feature...perhaps something like:

 

JavaArchive shaded = ShrinkWrap.create(JavaArchive.class, "shaded.jar");
UberJavaArchive container = ShrinkWrap.create(UberJavaArchive.class, "uber.zip");
container.addLibrary("a.jar");
container.addLibrary("b.jar");
UberJavaArchive.as(ShadedExporter.class).exportShaded(shaded);
System.out.println(shaded.toString(true));

 

prints (assuming a.jar has class A and b.jar has class B)

 

shaded.jar:
A.class
B.class

 

This functionality would be especially useful in build tools.