Building jar targeting multiple Java versions, including 9

Uwe Schindler uschindler at apache.org
Fri Aug 26 09:16:13 UTC 2016


Hi,

The Lucene team was also thinking about this, and we came to the conclusion that we might need to do 2 things:

- Build a Multi-Release JAR file and only compile new classes with Java 9 there and put them into the special folder of JAR file. We plan this to make use of VarHandles on Java 9 for ByteBuffer access. You would then have the same class 2 times in JAR file, one for older versions in the default place and a replacement for Java 9+
- In addition we would have a separate compilation unit with only a single module-info.java and that’s compiled with Java 9's Javac. The resulting file could be placed in the JAR file, too (not sure where: In root or in the multi-release place??? The latter would allow us to merge this with the previous point and we would not need 3 compilation runs).

We are using Apache Ant for building, so multiple invocations with javac are easy... I know that Apache Maven is also working on Multi-Release JAR files, I'd suggest to use this (if the 2nd point also works with module-info.class in the MR JAR as part of Java9 specific code).

Uwe

-----
Uwe Schindler
uschindler at apache.org 
ASF Member, Apache Lucene PMC / Committer
Bremen, Germany
http://lucene.apache.org/

> -----Original Message-----
> From: jigsaw-dev [mailto:jigsaw-dev-bounces at openjdk.java.net] On Behalf
> Of Oliver Gondža
> Sent: Friday, August 26, 2016 10:52 AM
> To: jigsaw-dev at openjdk.java.net
> Subject: Building jar targeting multiple Java versions, including 9
> 
> I am about to stretch support of my project from java 6, 7 and 8 to
> version 9 as well. It does not work there out of the box as it accesses
> sun.tools.attach.HotSpotVirtualMachine:
> 
> ```
> class MyClass (in unnamed module @0x4d14b6c2) cannot access class
> sun.tools.attach.HotSpotVirtualMachine (in module jdk.attach) because
> module jdk.attach does not export sun.tools.attach to unnamed module
> @0x4d14b6c2.
> ```
> 
> Before I had a chance to experiment with introducing modules to my
> application and declaring dependency on jdk.attach, my project refuses
> to compile on java 9 as soon as I add module-info.java as I instruct
> javac to produce java 6 bytecode (-target 1.6 -source 1.6):
> 
> ```
> modules are not supported in -source 1.6; use -source 9 or higher to
> enable modules
> ```
> 
> How does one take advantage of modules (in this case I have no choice)
> while keeping the project buildable for older Java versions? Or are
> users expected not to use modules until their apps drop support for
> older javas? I tried asking on SO[1] with no luck.
> 
> [1]
> http://stackoverflow.com/questions/38874646/building-modularized-java-
> application-targeting-both-java-9-and-older
> 
> Thank you
> --
> oliver
> Red Hat Jenkins Team



More information about the jigsaw-dev mailing list