Converting plain JARs to Java modules
Mandy Chung
mandy.chung at oracle.com
Sat Nov 5 09:59:45 PDT 2011
On 11/5/2011 3:27 AM, Alan Bateman wrote:
> On 05/11/2011 04:18, Glyn Normington wrote:
>> One of the issues any new module system faces is reusing existing
>> JARs. OSGi has tools like bnd and bundler to add OSGi metadata to a
>> JAR with sensible defaults.
>>
>> I was wondering if the Java module system will be capable of having
>> tools that automatically convert Jars to Java modules. I think this
>> will be important if we want to be able to depend on existing JARs in
>> a modular way.
>>
>> One specific issue is that since Java modules express their
>> dependencies on other Java modules rather than packages, it is not
>> possible to infer these dependencies by analysing the byte code of a
>> JAR. Has any thought been given to allowing Java modules to express
>> dependencies on packages rather than on other Java modules?
>>
> The migration and interop section of the requirements document [1]
> lists several requirements related to JAR files. Package-level
> dependencies is listed in the open requirements section.
>
> The current prototype has support for modular JAR files (essentially a
> module-info class in the top-level directory of the JAR file). You can
> specify a modular JAR file to the jmod command to install it as a
> module. Also the jar command has been updated with an option to
> generate a simple module-info.class. Note that it doesn't look at the
> static dependencies when generating the module-info but does look at
> the Main-Class and Class-Path attributes in manifest. For more
> complicated cases then it's better to write the module-info.java
> yourself and then use the jar command to add it to the JAR file.
Additional information:
You can refer to [2] about the jar command to transform a plain JAR file
to a modular JAR file.
There is an internal tool called ClassAnaylzer [3] that analyzes the
bytecode to generate the module dependencies. This is currently used by
the jdk build. We will likely provide a similar tool to help developers
for the dependency analysis.
[1]
http://openjdk.java.net/projects/jigsaw/doc/draft-java-module-system-requirements-12#_4
[2]
http://mail.openjdk.java.net/pipermail/jigsaw-dev/2011-August/001460.html
[3]
http://hg.openjdk.java.net/jigsaw/jigsaw/jdk/raw-file/tip/make/tools/classanalyzer/classanalyzer.html
More information about the jigsaw-dev
mailing list