9

I know that module-info.java is recognized by jdk9+

I wonder however whether module-info.java can still be used in combination with target level 8.

E.g. I want my library to be used in java9+ projects, which will recognize it as a module exporting specific packages, but also be used in java8 projects as a plain jar file.

Naman
  • 27,789
  • 26
  • 218
  • 353
Marinos An
  • 9,481
  • 6
  • 63
  • 96

1 Answers1

5

The Multi-Release JAR files are meant for the exact same purpose itself.

In a JDK that does not support MRJARs, only the classes and resources in the root directory will be visible, and the two packagings will be indistinguishable.

In a JDK that does support MRJARs, the directories corresponding to any later Java platform release would be ignored; it would search for classes and resources first in the Java platform-specific directory corresponding to the currently-running major Java platform release version, then search those for lower versions, and finally the JAR root.

On a Java 9 JDK, it would be as if there were a JAR-specific class path containing first the version 9 files, and then the JAR root; on a Java 8 JDK, this class path would contain only the JAR root.

For an example of this based on Maven, take a look at this - maven-jep238.

Community
  • 1
  • 1
Naman
  • 27,789
  • 26
  • 218
  • 353