How is Java 8 modules different from OSGi?

南笙酒味 提交于 2020-01-22 10:32:46

问题


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.

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

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?

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?

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.


回答1:


As written in the comments already, Java 8 will not ship with Jigsaw. Maybe 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.

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.

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.

Update March 2015

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.

The main differences (as of March 2015) are:

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



来源:https://stackoverflow.com/questions/20634993/how-is-java-8-modules-different-from-osgi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!