简体   繁体   English

Java 8模块与OSGi有何不同?

[英]How is Java 8 modules different from OSGi?

Java 8 with Project Jigsaw brings a module system to the SDK. 带有Project Jigsaw的Java 8为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. OSGi还提供了一个模块系统,但需要一个容器。 But apart from that what are the major difference among them. 但除此之外,它们之间的主要区别是什么。

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

The answer given to the question OSGi, Java Modularity and Jigsaw says that Jigsaw module system is probably necessary for JRE. 给出了OSGi,Java Modularity和Jigsaw这个问题的答案说Jigs的Jigsaw模块系统可能是必需的。 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? 通过JRE,我假​​设OP意味着Java标准库,如IO,CORBA,RMI,它们是用Java编写的,还是作为目标的类库实现? From reading the Jigsaw project page, I think it's the former. 从阅读Jigsaw项目页面,我认为它是前者。 If it's the later how does it even help other Java developers who write Java code? 如果是后者,它甚至会如何帮助编写Java代码的其他Java开发人员? The class libraries are written in C/C++. 类库是用C / C ++编写的。 Could anyone please clarify? 有人可以澄清一下吗?

This is not a OSGi vs Jigsaw. 这不是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. 我不是说OSGi已经过时了,我喜欢OSGi。 I am looking at the big picture, what the future directions are for OSGi itself. 我正在看大局,OSGi本身未来的发展方向。

As written in the comments already, Java 8 will not ship with Jigsaw. 正如已经在评论中写的那样,Java 8将不会附带Jigsaw。 Maybe Java 9. 也许是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, ie 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. 此外,在JavaOne 2013上,我参加了Mark Reinhold的演讲,听起来Jigsaw正在前进的方式对于Java开发人员来说通常不开放,即JRS将使用Jigsaw来模块化JRE(读作:rt.jar)本身但它不应该由Java开发人员使用。 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. 给出的原因之一是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. 无论如何,OSGi应该可以和Jigsaw一起运行。 But a lot libraries will break on Java 9 if they continue to use old sun.* packages or other internal JRE code. 但是如果他们继续使用旧的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. 在EclipseCon 2015上,Mark Reinhold发表了关于Java 9更新的主题演讲.Java 9将包含一个Java模块系统。 It is intended for the JRE/JDK and will also be available to any Java application that would like to use it. 它适用于JRE / JDK,也可供任何想要使用它的Java应用程序使用。 However, the scope changed a bit. 但是,范围有所改变。

The main differences (as of March 2015) are: 主要差异(截至2015年3月)是:

  • Class loaders - Jigsaw will not use class loader; 类加载器 - Jigsaw不会使用类加载器; it's up to runtimes (such as application servers or OSGi) to work with modules and class loaders 运行时(例如应用程序服务器或OSGi)可以使用模块和类加载器
  • Dependencies - Jigsaw will allow to specify dependency on modules by name but not at the package level 依赖关系 - Jigsaw将允许按名称指定对模块的依赖性,但不允许在包级别指定
  • Dynamic Services - The runtime services model provided by OSGi will not be provided by 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). Jigsaw不打算替换和/或与任何其他运行时或构建时模块系统(例如OSGi或Maven)竞争。 In fact, it's the intention of Jigsaw to be interoperable (somehow) with both. 事实上,Jigsaw的目的是与两者互操作(不知何故)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM