Converting plain JARs to Java modules
Glyn Normington
gnormington at vmware.com
Mon Nov 7 01:47:37 PST 2011
Thanks for those responses. I see that semi-automatic conversion of a existing JAR file to a modular JAR file is possible.
In case it's not obvious, please note that support for package level dependencies would permit a fully automatic conversion because it would then not be necessary to know the module name corresponding to each package dependency. A fully automatic converstion could be particularly useful in automatically serving up modularised versions of existing JARs, e.g. in a front end to Maven central.
Peter Kriens also makes the case for package level dependencies here, in case anyone missed it: http://www.osgi.org/blog/2011/10/what-to-depend-on.html
Regards,
Glyn
On 5 Nov 2011, at 16:59, Mandy Chung wrote:
> 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