Friday, June 12, 2009

Classpath hell just froze over?

Other blogs seems to drive this blog nowadays. Just read Classpath hell just froze over. This raises the questions where OSGi stands in the relation with JSR 294. I am not speaking from an official OSGi point of view, but I can of course give my personal opinion. I therefore posted a comment on the original blog but it turned out to be its own blog ...

JSR 294 contains 2 parts:
  • the module keyword
  •, with dependencies
I like the module keyword. We discussed this in 294 and we have some tentative agreement of the model, but the details still need to be worked out. However, agreement here is desirable and achievable.

The file? I have my severe doubts and have expressed this in the expert group. I do not think we fully understand the interactions with IDEs like Eclipse, IntelliJ, Netbeans, JDeveloper, etc. Currently, the command line with javac is completely driving the design while imho the IDE will be the common case for anyone needing modularity. Nobody needs modularity for a Hello World program, and letting this use case drive the design seems plain wrong.

One of the problems with this approach that I'm seeing is that a lot of dependencies are already specified in the sources (import package anyone?) and that a smart IDE can help find the proper modules to import those packages from. However, selecting package for import needs a wide range of modules because when you're developing, you want completion support in the IDE. However, when you have compiled your code, the compiler knows exactly which module was selecrted out of this wide scope it was compiled against.

And not to forget the build tools, they will start having to interpret the module-info file and link to the appropriate module system to find their class path. Today, a build tool tells the compiler its class path, in the future it would first have to compile or interpret the Java file. This alone will probably kill 90% of the ant scripts because the class path is used in other places then compiling. Also maven will have to start to interact with this.

This is not all. The current approach for is creating a meta-module system. Both Jigsaw, OSGi, and any other module systems can put their metadata in the file. This is the famous design by committee problem: let's each have it our own way and make the other optional. Good for vendors, bad for users. This is something that I am always fighting inside the OSGi. Having a meta-module system will cause severe fragmentation on the module layer. Some people hope for runtime interaction between module systems. Well, this will be very hard, if not impossible. Java module systems are just to complex to be able to map one to another without causing some severe pain.

Then about Jigsaw. It is very focused on breaking up the JDK into modules. I like the native installers but I dislike the fact that they put this native packaging stuff in my face. Java should abstract the platform so I can write code for any platform and distribute my code in a singular form. It's Java's original promise to deploy and manage this code on all the variety of VMs/OSs/packagers out there. There are hundreds of VM's and even more VM-package manager combinations. There is no way anybody can support all of these combinations. Write once, deploy everywhere, and then run anywhere? This all goes against the original promise and architecture of Java.

Jigsaw is too simple for the kind of applications in the enterprise space. Most of the class path problems are still in the module-path: split packages, no real hiding of classes (they will be protected by the module keyword only, not like OSGi invisible to other bundles), no multiple versions of the same JAR to solve hard dependency problems in large applications. Looking at Mark Reinhold's slides I think he agrees, Enterprise applications should be build on OSGi. However, small applications do not have to bother with modularity, so why allow Jigsaw to be used for applications at all? Unfortunately, if Jigsaw becomes part of the JDK delivery, people will start using it, causing immediate irreversible fragmentation.

Ok, to summarize. The module keyword is heavily supported by me and other OSGi people I know. It would allow us to put the bundles in the accessibility check of the Java VM. We're not there yet, but it looks good.

From a module system point of view I think we're moving into a direction of a meta-module system, where one of the two users of this meta-module system has an awful lot of homework left to do. After ten years of working on OSGi I would not yet dare to say that I completely understand Java module systems, I therefore shudder of the thought of a meta-module systems ...

Hope this helps to enlighten some issues.

Peter Kriens


  1. It does not :-) And frankly I do not want to completely understand. As a Java coder I want a good working module system... I want assemblies. I want "write code for any platform and distribute my code in a singular form".

    Tom (tbee)

  2. Well, at least we seem to be in agreement what we want :-)

    Peter Kriens

  3. Hi Peter, thanks for the detailed reply.

    First, what is the status of 294? Is it almost completed or is there a lot more work to do? I'm a bit confused since you are part of the expert group for that JSR, I thought you guys had to come to an agreement and then the implementations would follow. But it seems Jigsaw is already in the middle of that, I wonder what that means for the JSR.

    I'm also not sure what you mean by the "command line" (javac) driving the design. If I understand you correctly, you mean dependencies should be automatically detected by higher level tools like an IDE. I agree that this is desirable, but on the other hand I think these language features should be as IDE independent as possible and that you should be able (even if it could be a bit of a pain) to configure a relatively simple module from say vi and javac. In this case, the current approach doesn't seem to impose much on the tooling (the native packagin piece does btw).

    There's also no reason why a tool shouldn't be able to pick up a lot of the dependencies from import statements and general analysis of the project's classpath. But again, if you want to do it manually you have that option. And it does seem to be more user friendly than the MANIFEST file approach that OSGi currently uses.

    I do agree about the complexity of a "meta-module" system, but then again I thought this was a concession to OSGi. It would also be nice to see some examples on how OSGi bundles could interact with a Jigsaw enabled VM. Say you have a bundle for log4j, do you also have to have a Jigsaw version of it at runtime for it to work or will the module system be able to pick it up and have Jigsaw modules link to it?

    As for the native packaging, without knowing how it will work in other platforms outside of Linux, the whole concept is still a bit too nebulous to me. I can understand the goal, but I worry too about having to have all these native artifacts around when a simpler Java specific package format would do.

    Anyways, I wish I had caught up to this topic before the Q&A to ask more of the questions I listed on my blog post. I hope maybe we get a chance to get some answers, and I think for the OSGi side of things, see more technical details about why the current approach is technically better for Java 7.


  4. Re Jigsaw, it is already possible to dissect the JDK and stay compliant. You can in particular have an Eclipse RCP app packaged into a native installer having the size of the JRE.

  5. After the JavaEE 6 (JSR 316) presentation at DevoXX which followed the keynote about Jigsaw I also confronted the 316 Spec Lead with different wordings and paradigms behind the existing Java EE spec (e.g. "Module" is already used there to some extent) and upcoming ideas introduced by Jigsaw.

    So either it remains simply for SE or there has to be consolidation and (most likely Java EE 7 ;-) coordination on that, too.
    Including all these vendors most notably future Sun-owner Oracle who bet on OSGi massively with their Java EE containers.