Can I use module-info.java if target level is 8?

问题: 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 libr...

问题:

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.


回答1:

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.

  • 发表于 2019-01-11 05:53
  • 阅读 ( 267 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除