lundi 13 février 2023

In Java, what's the proper way of using an optional dependency without ClassNotFoundError?

I would like my projekt to switch at startup between backend libraries, with option to not shade both of them into resulting Jar, while having full compile-them visibility of both. I would also like to avoid loading backends using Class.forName.

Can you help me understand if any of these will lead to a ClassNotFoundError for unshaded library and which will not?

  1. Leaving an unused class field, of type from this library
  2. Leaving an unused method, with arguments or return from this library
  3. Referencing this library in a backend class that will only be loaded conditionally like backend = isNewBackend ? new FancyBackend() : new OldBackend()

If all of these result in error, is there an easier strategy for this?





Aucun commentaire:

Enregistrer un commentaire