Cross module single ServiceProvider for JPMS services

Alan Bateman Alan.Bateman at oracle.com
Sun Apr 19 14:22:45 UTC 2020


On 19/04/2020 15:00, Alex Sviridov wrote:
> Hi all,
>   
> Let's suppose we have modules (A, B, C..) and every module consumes and provides services.
> To find these services I want to create one util class, for example ServiceProvider that will be used
> by all modules to get necessary services. There are two ideas:
> *  to have one point to control providing services within system
> *  to avoid code duplication.
> However, I can't do it. The problem is that if we put ServiceProvider, for example, in module A,
> then it can find only services that module A uses (service is declared in  uses in module A module-info).
> Is it possible to do, if yes, then how?
If I read this correctly then we have code in module A looking to load 
service provider of type S but A's module declaration doesn't declares 
`uses S`. Have you tried the Module addUses method? That will add the 
"use" edge at run-time that should make this work.

-Alan.


More information about the jigsaw-dev mailing list