Java 8 模块与 OSGi 有何不同?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20634993/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:15:28  来源:igfitidea点击:

How is Java 8 modules different from OSGi?

javamoduleosgijigsaw

提问by

Java 8 with Project Jigsaw brings a module system to the SDK. I see it as a good thing as it's part of the package (built-in). OSGi also provides a module system, but requires a container. But apart from that what are the major difference among them.

带有 Project Jigsaw 的 Java 8 为 SDK 带来了一个模块系统。我认为这是一件好事,因为它是包(内置)的一部分。OSGi 也提供了一个模块系统,但需要一个容器。但除此之外,它们之间的主要区别是什么。

If I use OSGi, will I able to run it using the standard JDK 8 release?

如果我使用 OSGi,我能否使用标准的 JDK 8 版本运行它?

Will OSGi relevant when the default SDK includes such capabilities? My understanding is that both OSGi and Jigsaw can be used to write normal modular Java applications and not just ser based apps (servlets etc), right?

当默认 SDK 包含此类功能时,OSGi 是否相关?我的理解是 OSGi 和 Jigsaw 都可用于编写普通的模块化 Java 应用程序,而不仅仅是基于 ser 的应用程序(servlet 等),对吗?

The answer given to the question OSGi, Java Modularity and Jigsawsays that Jigsaw module system is probably necessary for JRE. By JRE, I assume the OP means the Java standard libraries like IO, CORBA, RMI which are written in Java or is it the class library implementations that underlies these which are the target? From reading the Jigsaw project page, I think it's the former. If it's the later how does it even help other Java developers who write Java code? The class libraries are written in C/C++. Could anyone please clarify?

OSGi、Java Modularity 和 Jigsaw问题的回答说 JRE 可能需要 Jigsaw 模块系统。对于 JRE,我认为 OP 是指用 Java 编写的 Java 标准库,如 IO、CORBA、RMI,还是作为目标的类库实现?从阅读 Jigsaw 项目页面来看,我认为是前者。如果是后者,它甚至如何帮助其他编写 Java 代码的 Java 开发人员?类库是用 C/C++ 编写的。有人可以澄清一下吗?

This is not a OSGi vs Jigsaw. I want to really understand which one to use. If I am to write a new application (be it desktop or server), I would like to be based on technologies that might not get obsolete by standard implementations and go abandon-ware. I am not saying OSGi is obsolete, I like OSGi. I am looking at the big picture, what the future directions are for OSGi itself.

这不是 OSGi 与 Jigsaw。我想真正了解使用哪个。如果我要编写一个新的应用程序(无论是桌面还是服务器),我希望基于可能不会被标准实现淘汰并被废弃的技术。我并不是说 OSGi 已经过时了,我喜欢 OSGi。我着眼于大局,OSGi 本身的未来方向是什么。

采纳答案by Gunnar

As written in the comments already, Java 8 will not ship with Jigsaw. Maybe Java 9.

正如评论中已经写的那样,Java 8 将不会附带 Jigsaw。也许是 Java 9。

Also, at JavaOne 2013 I attended a talk by Mark Reinhold and it sounded that the way Jigsaw is heading to is not generally open for Java developers, i.e. Jigsaw will be used by the JRE to modularize the JRE (read: rt.jar) itself but it's not supposed to be used by Java developers. One of the reasons given was that Jigsaw should not compete with existing solutions like Maven, OSGi, etc. Another reason was to shut down access to sun.* internal packages.

此外,在 JavaOne 2013 上,我参加了 Mark Reinhold 的演讲,听起来 Jigsaw 的发展方向通常对 Java 开发人员不开放,即 JRE 将使用 Jigsaw 来模块化 JRE(阅读:rt.jar)本身但它不应该被 Java 开发人员使用。给出的原因之一是 Jigsaw 不应与 Maven、OSGi 等现有解决方案竞争。另一个原因是关闭对 sun.* 内部包的访问。

But I also heard from someone attending the BOF later that day that there was some demand from the community to open Jigsaw for Java developers but I haven't heard any updates on that.

但我也从那天晚些时候参加 BOF 的人那里听说,社区有一些要求为 Java 开发人员打开 Jigsaw,但我没有听到任何更新。

In any case, OSGi should run fine with Jigsaw. But a lot libraries will break on Java 9 if they continue to use old sun.* packages or other internal JRE code.

无论如何,OSGi 应该可以与 Jigsaw 一起正常运行。但是如果继续使用旧的 sun.* 包或其他内部 JRE 代码,很多库会在 Java 9 上崩溃。

Update March 2015

2015 年 3 月更新

At EclipseCon 2015 Mark Reinhold gave a keynote with an update on Java 9. Java 9 will include a module system for Java. It is intended for the JRE/JDK and will also be available to any Java application that would like to use it. However, the scope changed a bit.

在 EclipseCon 2015 上,Mark Reinhold 发表了关于 Java 9 更新的主题演讲。Java 9 将包含一个 Java 模块系统。它适用于 JRE/JDK,也可用于任何想要使用它的 Java 应用程序。但是,范围发生了一些变化。

The main differences (as of March 2015) are:

主要区别(截至 2015 年 3 月)是:

  • Class loaders- Jigsaw will not use class loader; it's up to runtimes (such as application servers or OSGi) to work with modules and class loaders
  • Dependencies- Jigsaw will allow to specify dependency on modules by name but not at the package level
  • Dynamic Services- The runtime services model provided by OSGi will not be provided by Jigsaw
  • 类加载器- Jigsaw 不会使用类加载器;使用模块和类加载器取决于运行时(例如应用程序服务器或 OSGi)
  • 依赖项- Jigsaw 将允许按名称指定对模块的依赖项,但不能在包级别指定依赖项
  • 动态服务- Jigsaw 不会提供 OSGi 提供的运行时服务模型

Jigsaw is not intended to replace and/or compete with any other runtime or build time module system (such as OSGi or Maven). In fact, it's the intention of Jigsaw to be interoperable (somehow) with both.

Jigsaw 无意取代和/或与任何其他运行时或构建时模块系统(例如 OSGi 或 Maven)竞争。事实上,Jigsaw 的意图是(以某种方式)与两者互操作。