Creating modules with JDK8
Alan Bateman
Alan.Bateman at oracle.com
Sun Nov 29 08:18:24 UTC 2015
On 27/11/2015 19:52, Simon Ochsenreither wrote:
> Hi everyone,
>
> sorry if this has been asked already, I couldn't find it in the
> documentation.
>
> Will the code that creates *.jmod files from *.class files be runnable
> on earlier versions of the JDK, or available via Maven Central?
>
I suspect there is a more general question here as to how you might
release a library that works on JDK 8 but can also work as a module with
JDK 9, is that right?
If so then check out modular JARs (as Rémi suggested) as they are just
regular JAR files with a compiled module declaration in the top-level
directory of the JAR file. If the code that is packaged in the JAR file
is compiled for JDK 8 then it creates the potential for the library to
work as a regular JAR file on the class path with JDK 8 (or 9) or as a
module on the module path with JDK 9+.
There is clearly a lot of opportunity for tooling. I think most builds
today compile with an older JDK whereas the transition to modules brings
up the question as to whether to compile with JDK 9 and use the new
javac -release option to compile the code JDK 8, and compile the module
declaration for JDK 9. Also with multi-release JAR files coming in JDK 9
(JEP 238) then it's possible to have release specific code in the JAR
file too. All told, it could complicates the build a bit and this is
where good tooling could help a lot.
As you bring up JMOD files then it's just an alternative packaging
format. At this time then it's mostly for modules that are intended to
be linked into a run-time image (meaning a JRE, JDK or custom run-time)
- it isn't currently an execution format. I could imagine Maven plugins
supporting it as a new artifact type in the future.
-Alan
More information about the jigsaw-dev
mailing list