为什么Java 9引入了JMOD文件格式? [英] Why did Java 9 introduce the JMOD file format?

查看:1240
本文介绍了为什么Java 9引入了JMOD文件格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 9通过三种方式将编译后的代码打包到文件中:

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

  • JAR
  • JMOD
  • JIMAGE

JIMAGE已针对速度和空间进行了优化,并且在运行时被JVM使用,因此引入JIMAGE的原因很有意义. JIMAGE文件不应该发布到Maven仓库,也不应该在编译或链接时使用.

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.

文档声称JMOD可以存储本机代码和JAR文件无法存储的其他内容,并且开发人员可以制作和分发自己的JMOD文件. JDK随附jmods/目录,其中包含JDK的所有模块,供用户依赖.

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.

问题:

  • 为什么Java 9引入了JMOD文件格式?
  • 图书馆作者应分发JMOD文件或JAR文件,还是同时分发这两者?
  • 是否应将jmod文件发布到Maven仓库?

推荐答案

以下是 JEP 261的引号:模块系统,其中包含有关JMOD文件的部分.

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

为什么?

来自 JEP 261 :

新的JMOD格式超越了JAR文件,可以包含本机代码, 配置文件以及其他不适合的数据 自然,如果有的话,也可以放入JAR文件中.

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.

JMOD文件的最终格式是一个未解决的问题,但现在它是 基于ZIP文件.

The final format of JMOD files is an open issue, but for now it is based on ZIP files.

开发人员应发布JMOD文件吗?

请注意,JMOD文件似乎是在编译时和链接时合并本机代码(以及其他方法)的一种方式.来自 JEP 261 :

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文件可以在编译时和链接时使用,但不能在运行时使用 时间.

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

(说实话,我不确定在JDK 9之前如何发布本机代码.)对于绝大多数开发人员(没有本机库或其他极端情况),我们将只发布模块化jar.

(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.

这篇关于为什么Java 9引入了JMOD文件格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆