How is Java 8 modules different from OSGi?

后端 未结 1 384
暖寄归人
暖寄归人 2021-02-07 00:04

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

相关标签:
1条回答
  • 2021-02-07 01:04

    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.

    0 讨论(0)
提交回复
热议问题