Class loading question in OpenMRS 1.12

We are currently using OpenMRS version 1.12. I am wondering the best way to handle duplicate libraries with different versions across modules when one of the modules is not developed by our group? For example:

Module A includes library-A-version2.0 (developed by our organization) in the lib folder Module B includes library-A-version1.0 (developed by some other organization) in the lib folder

I see that OpenMRS allows modules to use different versions of the same library that OpenMRS may already include. However, in regards to the same library being included in multiple modules, it looks like the OpenmrsClassLoader gets a set of ModuleClassLoader objects that contain the package of the class name that needs to be loaded. The example above would have both class loaders in the set if I am understanding the code correctly, which could then result in the class being loaded from the wrong module.

What is the best way to handle this situation? We want to use the latest version of the library, but the other module includes an older version.

Thanks, David Ely Software Developer Children’s Health Services Research IU School of Medicine Phone: 317-278-1642 Email: davely@iu.edu

Visibility of a given library is scoped to a single module’s classloader i.e. that of the module in which it was packaged unless another module explicitly says it requires another module, that’s the only time when the visibility scope extends to the dependent module’s classloader too. This means modules A and B can co-exist with no classloading issues with the same library but different versions as long as they don’t depend on each other. Do your modules depend on each other?

1 Like

Thank you for the response. No, our modules do not depend on each other. I will take a closer look at the code in OpenmrsClassLoader.loadClass(), as I thought I was seeing that it was possible for the call to ModuleFactory.getModuleClassLoadersForPackage() to return a set which contained both the ModuleClassLoader for modules A and B, which could result in the class being loaded from the wrong module.

@wyclif your post made my day. Thanks a lot for that small but very important detail!