Hi,
I have a plugin mechanism in my application. The plugins are defines by an interface and are loaded via URLClassLoader. A plugin can also have resources, loaded via ResourceBundle.getBundle.
Whenever a plugin's method is called, I do this, before it is called:
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(pluginClassLoaders.get(pluginClass.cast(proxy)));
// Invoke plugin method
Thread.currentThread().setContextClassLoader(oldLoader);
The plugin methods are called in their own thread, that means, when I want to open a window I need to do it on the JavaFX Application Thread with Platform.runLater.
The problem is, that in the run method of the Platform.runLater, my Thread.currentThread().getContextClassLoader() is not my URLClassLoader but the Application Classloader.
Why I need this?
I don't want the plugin developer to always keep in mind, that he has to pass the correct class loader (of his classes) into the ResourceBundle.getBundle method.
Instead I thought I could rely on Thread.currentThread().getContextClassLoader(), which is set in the main application, to load the correct bundle.
It would work, but not if I load the bundle inside the JavaFX Application Thread (but which makes the most sense for UI development).
So my goal was to have a convenient method like:
String getResource(String bundle, String key)
{
return ResourceBundle.getBundle(bundle).getString(key), Thread.currentThread().getContextClassLoader());
}
To avoid passing the classloader every time.
Any ideas on this?