Converting plain JARs to Java modules
Alan Bateman
Alan.Bateman at oracle.com
Sat Nov 5 03:27:50 PDT 2011
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.
-Alan.
[1]
http://openjdk.java.net/projects/jigsaw/doc/draft-java-module-system-requirements-12#_4
More information about the jigsaw-dev
mailing list