我知道module-info.java是被jdk9+识别的
但是我想知道 module-info.java 是否仍然可以与目标级别 8 结合使用。
例如我希望我的库在 java9+ 项目中使用,它将把它识别为导出特定包的模块,但也可以在 java8 项目中作为普通 jar 文件使用。
最佳答案
The Multi-Release JAR files本身是为了完全相同的目的。
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.
有关基于 Maven 的示例,请查看此 - maven-jep238 .
关于java - 如果目标级别是 8,我可以使用 module-info.java 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54115591/