I have a JAR application, M.jar that supports extensions to be written and loaded dynamically. The application requires that the classes implement interface E and be called NE.
Now, the following is what I'm trying to do,
- Write an extension API1 and load it to M.
- Write another extension APIUser, load it to M and make use of API1.
Please see below diagram for what I'm trying to do here.
I know that M.jar uses a custom ClassLoader because it requires any extension be named AE only.
I tried the ServiceProvider, ServiceProviderInterface method as described here but that did not work. I believe this is because API's classes are not in M's classpath and hence APIUser cannot find it.
I want to know,
- If it is feasible to use APIUser's ClassLoader to load API's class and initialize it for use in APIUser.
- Is it possible for M to block/isolate API's ClassLoader from any other extensions? I think it can be based off of this answer.
- What other means are there to load API's class in APIUser1 or APIUSer2 ... and maintain only one instance of API's class? (i.e singleton)