My Java library should be compatible with Java 8 and Java 9. For running with Java 9 we need some of the Java 9 modules.
I know that I can add it via command line wi
Modules express dependencies in their module declaration, so you have to create a module-info.java
, define your module's name, dependencies (in your case with requires java.activation
and requires java.xml.bind
) and exports (more on that later).
The module declaration must be compiled by a Java 9 compiler to create a module descriptor module-info.class
that belongs into the JAR's root folder.
Java versions prior to 9 will ignore the module-info.class
, which means if you compile the rest of your code for Java 8 (either by using javac 8
or by using the new --release
flag on javac 9
), your library still functions on that version.
Even Java 9 will only process your JAR as a module if it ends up on the module path. Only then will it see the requires
clauses and include the Java EE modules you are using in the module graph. This means client using your library on Java 9's class path will still have to manually add the two modules via command line.
If your module is used on the module path, the accessibility rules make sure that:
This means:
Particularly the second point can be tough if you depend on projects that are not yet modularized but that's another question.