24

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.

Community
  • 1
  • 1
  • 3
    If you are planning a project, be aware of this statement from the [JDK 8 public review](https://jcp.org/en/jsr/detail?id=337): _The original request for this Specification proposed to include a module system, and to use that system to modularize the Platform itself. That feature was, however, deferred to a future release in order to allow sufficient time for the broad evaluation, review, and feedback which such a profound change to the Platform demands._ – McDowell Dec 17 '13 at 13:53
  • 6
    Yes. Jigsaw is out of Java 8. Furthermore, the Jigsaw project will have it goals and requirements rethought, http://mail.openjdk.java.net/pipermail/jigsaw-dev/2013-August/003328.html, and perhaps be part of Java 9. So this means we don't know what Jigsaw will be nor when it will appear in Java. So it hard to make any comparison to OSGi which is here now. – BJ Hargrave Dec 17 '13 at 14:00
  • 2
    Also note that there is the project Penrose: http://openjdk.java.net/projects/penrose/ "The goal of this Project is to explore and implement interoperability between the Jigsaw Project and OSGi." – Puce Jan 09 '14 at 14:42

1 Answers1

26

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.

Gunnar
  • 2,264
  • 17
  • 31
  • Just found an article from pre-Java 7 about Jigsaw and thought how perfect it would be for some code I was writing and figured SURELY it was in Java 8....Nope. – JReader Jul 08 '15 at 15:21
  • To future Java version 10,11 or even 111 users. Do you already have Jigsaw? I may have to live a healthy life after all to be around until it arrives. – dbalakirev Nov 07 '16 at 13:02
  • Now that Java 9/Jigsaw is out: Is the description from 2015 provided above still valid? – opncow Mar 18 '19 at 17:51
  • Still valid as of Java 11/12 as I can see. Some libraries started adopting/supporting it. – Gunnar Mar 19 '19 at 19:48