I developed an application that loads plugins dinamicaly according to this tutorial: http://solitarygeek.com/java/a-simple-pluggable-java-application, but i came across a problem. In my main application i have a class with static methods, how can i access that class from inside my plugins? When i try to access the class from the loaded plugin it gives me an error that class was not found, although the plugin and the application are running. Thank you
3 Answers
In the plugin architecture you are not supposed to access the plugin implementation class directly. What you have at your disposal is the interface through which you'll get access to an instance of your implementation class. That obviously precludes any static methods. Refactor those methods into instance methods and expose them via the interface.
2 Comments
Sounds like a class loader problem. The class loader that loads your plugin does not see your main class. Difficult to say any more without code samples.
1 Comment
I managed to resolve my problem by creting a classloader with the application classloader as parent classloader like this:
URLClassLoader MyLoader = new URLClassLoader(new URL[]{},MyClass.class.getClassLoader()), and now, all the classes loaded in my application are visible to the plugin that is loaded with MyLoader