I'm trying to transport arbitrary Java objects from workspace to my plugin by serializing them to XML using XStream. This works fine (using SIMON), but when trying to restore them on plugin-site, I get a CannotResolveClassException (obviously). So I'd like to somehow include workspace classes in my plugin's build path, in order to make workspace types available inside my plugin and therefore be able to restore objects.
Asked
Active
Viewed 220 times
0
-
Your plugin needs access to the java classes. Are they in a plugin already, or a java project? – Paul Webster Jun 25 '12 at 11:31
-
They are in an ordinary Java project, not a plugin. – Cedric Reichenbach Jun 25 '12 at 16:00
-
Eclipse plugins are OSGi bundles, so you have to expose your java classes to OSGi somehow (either contained in your plugin or as their own plugins). See http://stackoverflow.com/q/3594024/713646 and http://stackoverflow.com/q/762721/713646 as they explain the relationship between jars and OSGi. – Paul Webster Jun 25 '12 at 16:10
-
Thanks for your suggestion... Hmm, but I'm writing a plugin to visualize objects at runtime AND leave them interoperable post mortem (i.e. I need to store them). But that leads to problems if those (arbitrary) user types are not known at my plugin (running in Eclipse VM). Anyway, I cannot expect users to build OSGi bundles just to be able to use this plugin... – Cedric Reichenbach Jun 25 '12 at 22:01
-
if it's like hosting a another java app in your plugin, you could (in theory) create and load their code using a URLClassloader. You would be manipulating their objects entirely via reflection. – Paul Webster Jun 26 '12 at 11:03
-
Ha, that's exact the same thing I found out today, I'm gonna try this... Thanks anyway... – Cedric Reichenbach Jun 26 '12 at 12:55
-
The more OSGi version of that is to dynamically wrap contributed jars in OSGi bundles, and then ask the OSGi framework to load them for you. There are OSGi headers for "add all packages to my classpath", for example. – Paul Webster Jun 27 '12 at 14:20
1 Answers
0
I've managed to do this by using a URLClassLoader
and going throug all projects in workspace (using the Resources Plugin) and adding all subfolders (recursively) to this classLoader.
I know it's some kind of brute-force, but it's working and I couldn't figure out how to determine the build target folder (not always /bin).

Cedric Reichenbach
- 8,970
- 6
- 54
- 89