Equivalent to an ObjectOutputStream object, preserving not only its state, but the entire object?

I allow the user to import plugin-like classes from a remote location using URLClassLoader, so these imported classes DO NOT exist in the build path (however, they all implement the IPlugin interface, which is included).

I suggested that you can simply use ObjectOutputStream to save all loaded plugins to a file and then read them with ObjectInputStream. However, this is not so, since all that it saves is the state of the object, and not containing logic (i.e.Methods).

I would like to save the list of loaded plugins (activePlugins) using ObjectOutputStream:

ObjectOutputStream oos = new ObjectOutputStream(*fileoutputstream*);
oos.writeObject(activePlugins);
oos.close();

Then at another runtime load / restore all of these plugins using ObjectInputStream:

ObjectInputStream ois = new ObjectInputStream(*fileinputstream*);
activePlugins = (ArrayList<IPlugin>) ois.readObject();

( - ), haywire. , , - , .. .

+5
3

. - URLClassLoader, . URLClassLoader - . , , - ( , ).

+4

RMI. , ( ) .

, .

+1

Altought Java is not my main programming platform, I saw the same problem in other "frameworks" such as PHP, Delphi and C #.

One solution is to declare class files and paths.

Another suggestion is that since you figured out you don't care about the state of the logic, only ("data"), you can declare a generic class that stores the value of the properties.

0
source

All Articles