java - 如果目标级别是 8,我可以使用 module-info.java 吗?

标签 java java-9 java-platform-module-system module-info multi-release-jar

我知道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/

相关文章:

java - 如何将 json 的 Maven 依赖项添加到 >= Java 9 中的模块

java - HTTP 状态 403 - 访问被拒绝 Spring 安全

java - 使用 Collat​​or 对带重音符号的字符串进行排序

java - 什么是通用区域设置数据存储库 (CLDR) - JDK 9

java - Java 9 模块化应用程序中的 Logback 不起作用

java - 什么是非法反射访问?

java - 无法识别的选项 : --print-module-descriptor

Java 定时器计数太快

java - Eclipse 关于 SortedMap 未重新声明 equals() 和 hashCode() 的警告

java - Java 9 也适用于 WAR 文件吗?