1

I am working on a task that migrates the OSGI modules to Java SPI modules. Let's say I have three OSGI(A, B, C) modules. So each module has a class for activation and activation happening when starting the servers(at the beginning). Service registration and some other required method executions happening on the activation(@acctivate) class. Service, Service implementation, and Service registration are included in the same module.

but when migrating I have some questions,

1)Each OSGI module has a different class path. Therefore I can have different versions of dependency jars for the different modules ( A - aaa.jar(version-1.0), B - aaa.jar(version-2.0). But all the SPI modules will load in the same class path. So is it possible to have different versions of dependency jars for the different modules?

2)In Java SPI we don't have an activation class. Service loader is to load service implementations. is this lazy loading the solution for java SPI?

3)As I mentioned earlier. Some other method executions are happening in the OSGi activation class. So it will execute those methods when bundle activation happens(Starting the server ).what can be the solution in SPI modules(there is no activation class)?

Shamly
  • 23
  • 4
  • There is [a ServiceLoader.load method](https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/util/ServiceLoader.html#load(java.lang.Class,java.lang.ClassLoader)) that accepts a ClassLoader. As for running on server startup… why is it necessary to run immediately? Why can’t your classes perform initialization when those classes are loaded, using static initialization blocks (or even regular constructors)? – VGR Apr 10 '22 at 17:24
  • 1
    I’m not sure what you mean with “SPI modules”. When you are talking about ordinary Java modules, they are not loaded though the class path at all. Within one module layer, conflicting packages are not allowed, so if your different versions of a library keep using the same package names, they must be placed into different module layers. – Holger Aug 23 '22 at 11:03

0 Answers0