File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes How to Load Serialized Plugins? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to Load Serialized Plugins?" Watch "How to Load Serialized Plugins?" New topic

How to Load Serialized Plugins?

Jeronimo Backes

Joined: Sep 20, 2004
Posts: 29
My application must work with plugins, where the main project is formed by a set of plugins whose implementation I don't know, they just implement a Interface called Plugin (original, huh?)

Every plugin has these two methods:

public void savePlugin(File f); wich is responsible for saving it in a file that my project specified.


public PluginLoader getPluginLoader(); wich returns a Abstract class with the single method open(File f);

Then, when I save my project, I do that:

It saves myProject as expected, and every instance of Plugin used by it.

Now the problem arises:

Imagine that I have a plugin called Foo. Foo has its own implementation of a class FooLoader extending PluginLoader and implementing the method open(File f). That class is returned by getPluginLoader() and it knows how to load a saved file containing a Foo instance.

So, when I try to load a saved project, i do that:

And I got a ClassNotFoundException. I know it is because the jvm can't find the class FooLoader inside the jar that contains the plugin Foo. The Foo plugin is loaded by getting the main class inside the jar that contains it.

What can I do to deserialize FooLoader?

The art of being crazy is to NEVER commit the crazyness of being normal.
Jeronimo Backes

Joined: Sep 20, 2004
Posts: 29
That's it:

Now, I can save my project with:

And that's the end of two days of pain!
I agree. Here's the link:
subject: How to Load Serialized Plugins?
It's not a secret anymore!