lundi 26 juin 2017

Get reference to Class from another class loader at runtime in JAVA

I am running some domain specific scripts in a new thread of an application. The classloader in the thread only has all the classes of the application.

The application also has a module that loads additional classes in jars in a folder at runtime (classes created outside of the application), providing additional functionalities to other parts of the application.

Unfortunately, these two classloaders are not merged and when running my scripts I cannot load any class that I know is there in one of the external jars.

Tried this.getClass().getClassLoader().loadClass("external.cls") no go. Also tried Reflections reflections = new Reflections("external.cls") also no go.

Is there a way to gain access to those classes in my script running thread at runtime? Something like:

  • Gain access to another class loader that loaded the external class?
  • Use reflection to get the external class from the two class loaders?
  • Load the external jars again in my script running thread?




Aucun commentaire:

Enregistrer un commentaire