Extending java.base module
Alan.Bateman at oracle.com
Wed Feb 15 10:55:16 UTC 2017
On 15/02/2017 08:36, Langer, Christoph wrote:
> Hi Jigsaw experts,
> as you might or might not know, we have an own JDK implementation with some extension code that is quite interwoven with the jdk.
> Now I'm looking into how this coding can be spread into a good module structure for jdk9. And I'm not a crack yet on using the module system though I've read quite a bit into the spec documentation available so far;-)
> The first point for me is that we have to place some of our coding in the java.base module as we used to add private fields and methods to basic classes such as java.lang.Thread or java.lang.Exception. However, I don't want to have so much of our stuff in java.base and rather think that it should live in its own module. So the question here is if it is possible to call code of other modules from java.base, e.g. via the Service Provider interface? I see that I can define a service in java.base and specify some "uses" statement in module-info. But will my implementation of such a service from other modules be available to java.base?
> Also I'm contemplating about this requirement: I have a class which I would need somewhere in java.base but I'd also like to export it in the public API of my own extension module. So, if I create the class in java.base, I'm not allowed to export this class publicly, unqualified, right? But when I have it living in my extension module, then java.base would not see it. What can I do? Probably create some inherited class in my extension module that extends from the java.base impl and export this??
> I'm hoping that those are easy questions for you and you can give me some helpful answers.
Yes, services is the way to do this. The jdk.net module is one example,
there are several others. The other thing to be aware of is the
module-info.java.extra files to augment the module declarations during
the build, I suspect you'll end up using that.
More information about the jigsaw-dev