java9使用jimage,为什么Java 9引入了JMOD文件格式?

Java9引入了JMOD文件格式,旨在包含不能直接放入JAR文件的元素,如本地代码和配置文件。JMOD文件适用于编译时和链接时,但不应用于运行时。开发者通常会发布模块化的JAR文件,而不是JMOD文件。对于包含本地库的特殊情况,开发者可能需要提供JMOD文件。JMOD不应发布到Maven仓库。
摘要由CSDN通过智能技术生成

Java 9 has three ways to package compiled code in files:

JAR

JMOD

JIMAGE

JIMAGE is optimized for speed and space and used by the JVM at runtime so it makes sense why JIMAGE was introduced. JIMAGE files are not supposed to be published to maven repos or used at compile or link time.

The docs claim that JMOD can store native code and other things that can't be stored by JAR files and that developers can make and distribute their own JMOD files. The JDK ships with jmods/ directory containing all the modules of the JDK for users to depend on.

Questions:

Why did Java 9 introduce the JMOD file format?

Should a library author distribute a JMOD file or a JAR file or both?

Should jmod files be published to maven repos?

解决方案

Here are some quotes from JEP 261: Module System, which contains a section on JMOD files.

Why?

The new JMOD format goes beyond JAR files to include native code,

configuration files, and other kinds of data that do not fit

naturally, if at all, into JAR files.

and

The final format of JMOD files is an open issue, but for now it is

based on ZIP files.

Should a developer publish JMOD files?

Note that JMOD files appear to be a way to incorporate native code (among other things) at compile-time and link-time. From JEP 261:

JMOD files can be used at compile time and link time, but not at run

time.

(To be honest, I'm not sure how native code is published pre-JDK 9.) For the vast majority of developers (without native libraries or other corner-cases), we will merely publish modular jars.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值