Reputation: 606
I am currently developing a plugin in Eclipse. I have encountered a problem with the following code:
XYZ object1 = XYZ(object2);
where the said line throws an exception:
Caused by: java.lang.ClassCastException: abc.XYZ cannot be cast to abc.XYZ
XYZ class is from another plugin. Unfortunately, the said plugin does not have its packages visible. So, setting it as a dependency threw a ClassDefNotFound
exception.
Luckily, I have the .jar
of the plugin and added it to my plugin's build path. When I did so, it still returned a ClassDefNotFound
exception. I looked around and found out that for plugins, the referenced libraries are not 'detected' by the JVM automatically, and so, I followed the solution to add the said jar to the MANIFEST.MF
and to the bin.includes
section of my plugin's build.properties
.
After following the said solution, I tried again and now I have classCastException. Atleast, at this point, the class XYZ
from the jar file is now being loaded. Doing some research, I found out that the classloaders of both XYZ
classes are different. I am quite stuck on what steps should I do.
Here's the summary of the whole problem:
It would be great if anyone has a solution to this problem or any inputs on what I can do to fix this.
Thank you in advance for any help/input that will be provided.
Upvotes: 0
Views: 208
Reputation: 111216
You can't do this. The Eclipse plugin system is designed to prevent you accessing classes which are not exported.
Including the plugin jar in your plugin will always use a different class loader from the class loader and you will get the class cast exception.
The only way to access these classes is for the other plugin to be modified to export these classes.
Upvotes: 1