1

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 3

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your response, but it seems that there is a way to do it
There may be a way to do it if you tamper with the plugin infrastructure implementation, but it will just break that implementation. It is the fundamental requirement of a plugin architecture that the plugin should be seen from other plugins only through its public interface. There must be no static dependencies to another plugin's implementation classes as the other plugin has no right to assume they will be there.
0

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

Thank you, i think you are right, i switched from sysLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); to sysLoader = (URLClassLoader) MainClass.class.getClassLoader(); and it seems to work
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.