Java 8模块与OSGi有何不同? [英] How is Java 8 modules different from OSGi?

查看:124
本文介绍了Java 8模块与OSGi有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

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

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?

OSGi,Java Modularity and Jigsaw 说JIR需要Jigsaw模块系统。通过JRE,我假​​设OP意味着Java标准库,如IO,CORBA,RMI,它们是用Java编写的,还是作为目标的类库实现?从阅读Jigsaw项目页面,我认为它是前者。如果是后者,它如何帮助编写Java代码的其他Java开发人员?类库是用C / C ++编写的。有人可以澄清一下吗?

The answer given to the question OSGi, Java Modularity and Jigsaw says 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与Jigsaw。我想真正理解使用哪一个。如果我要编写一个新的应用程序(无论是桌面还是服务器),我希望基于标准实现可能不会过时的技术并放弃使用。我不是说OSGi已经过时了,我喜欢OSGi。我正在看大局,OSGi本身未来的发展方向。

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.

推荐答案

正如评论中所述,Java 8不会附带Jigsaw。也许是Java 9.

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

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

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.

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

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.

无论如何,OSGi应该可以和Jigsaw一起运行。但是如果他们继续使用旧的sun。*包或其他内部JRE代码,很多库都将在Java 9上中断。

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.

2015年3月更新

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

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.

主要差异(截至2015年3月)是:

The main differences (as of March 2015) are:


  • 类加载器 - Jigsaw不会使用类加载器;

  • 依赖项 - Jigsaw将允许按名称指定对模块的依赖性,但由运行时(例如应用程序服务器或OSGi)来处理模块和类加载器
  • 不在包级别
  • 动态服务 - Jigsaw将不提供OSGi提供的运行时服务模型

  • 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或Maven)竞争。实际上,Jigsaw的意图是以某种方式与两者互操作。

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.

这篇关于Java 8模块与OSGi有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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