Modular JAR file support

Mandy Chung mandy.chung at oracle.com
Tue Apr 5 15:46:54 PDT 2011



I have a prototype to support a modular JAR file be installed on a module library.

A modular JAR file is a JAR file with a module-info.class entry that can be
installed as a module in a module library as well as used as an ordinary
JAR on the class path.  This will allow library developers to produce one
single file as a traditional application (that can run in an older JDK
release e.g. JDK 7) as well as a modular application.

For example, hello.jar and world.jar are modular JAR files and each
contains module-info.class entry.  hello.jar also contains the manifest.

$ jar tvf hello.jar
        0 Tue Apr 05 15:16:16 PDT 2011 META-INF/
    130 Tue Apr 05 15:16:16 PDT 2011 META-INF/MANIFEST.MF
   276 Tue Apr 05 15:16:14 PDT 2011 module-info.class
       0 Tue Apr 05 15:16:14 PDT 2011 com/
       0 Tue Apr 05 15:16:14 PDT 2011 com/greetings/
   639 Tue Apr 05 15:16:14 PDT 2011 com/greetings/Hello.class

$ jar tvf world.jar
       0 Tue Apr 05 15:16:16 PDT 2011 META-INF/
     74 Tue Apr 05 15:16:16 PDT 2011 META-INF/MANIFEST.MF
   192 Tue Apr 05 15:16:14 PDT 2011 module-info.class
       0 Tue Apr 05 15:16:14 PDT 2011 org/
       0 Tue Apr 05 15:16:14 PDT 2011 org/astro/
  276 Tue Apr 05 15:16:14 PDT 2011 org/astro/World.class

$ cat com.greetings/manifest
Class-Path: world.jar
Main-Class: com.greetings/Hello

$ cat com.greetings/module-info.java
module com.greetings @ 0.1 {
     requires org.astro @ 1.2;
     class com.greetings.Hello;
}

$ cat org.astro/module-info.java
module org.astro @ 1.2 { }

The modular file can be launched as a ordinary JAR file:

$ java -jar hello.jar
Hello, world!

Or install them in a module library and launch the modular app

$ jmod install hello.jar world.jar
$ java -m com.greetings
Hello, world!


Webrev at:
     http://cr.openjdk.java.net/~mchung/jigsaw/webrevs/modular-jar-file/

We'll deal with the signed modular JAR file next.   When installing
a signed modular JAR file, it will use the current signed jar verification
mechanism and the signer's certchain and timestamp will be stored
in the module library in the same way as a signed module file is installed.

Mandy




More information about the jigsaw-dev mailing list