2 Replies Latest reply on Oct 16, 2010 4:45 AM by aslak

    UberJar archive type

    dan.j.allen

      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.

        • 1. Re: UberJar archive type
          aslak
          ShrinKWrap.create(JavaArchive.class)
               .as(ZipImporter.class)
                    .importZip("a.jar")
                    .importZip("b.jar")
               .as(ZipExporter.class)
                    .exportTo(new File("shaded.jar"));
          

           

           

          ??

          • 2. Re: UberJar archive type
            aslak
            JavaArchive a = ..;
            JavaArchive b = ..;
             
            ShrinKWrap.create(JavaArchive.class)
            .merge(a)
            .merge(b)
            .as(ZipExporter.class)
            .exportTo(new File("shaded.jar"));