Compile module-info.java using a Java 9+ compiler.Compile all sources except module-info.java using the appropriate javac flags to provide compatibility with the target pre-Java 9 version.The standard way to do this implies invoking the Java compiler twice: This means that a modular jar compatible with a pre-Java 9 release can be produced by creating a normal jar for the target version and inserting a module descriptor into it. The module descriptor is ignored when running on Java 8 and older versions, because module-info is not a legal Java identifier. This module descriptor is typically produced by compiling a corresponding module-info.java file. So, how can you build a library that is both modularized and compatible with Java versions before 9?Ī modular jar is just a normal jar that includes a module-info.class file, which represents the module descriptor. However, the JPMS is implemented only by Java 9 and newer versions. At the same time, you may consider modularizing your library in order to make it attractive for applications that take full advantage of the Java Platform Module System (JPMS). One way to increase the number of applications that can include your library is to make it compatible with older Java versions. If you’re a library author, you probably want to see your library used in a large number of applications.
0 Comments
Leave a Reply. |