Building jar targeting multiple Java versions, including 9

Oliver Gondža ogondza at gmail.com
Fri Aug 26 08:52:03 UTC 2016


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