Dynamic Class Loading
I have a problem with dynamic class loading, the problem is that i have a main application in which u can plugin other applications. This works fine, but one of the applications i want to plugin also uses dynamic class-loading. So i have a plugin inside a plugin.
The weird thing is that the jar i want to plugin into the main application works fine, and there is no problem with dynamic class loading, but when i want to plugin that application into the main application java gives a classcastexception.
This is the package structure from all 3 applications, because i think the problem lies there.
Plugin 1 (the one that i plugin into the main application)
Plugin 2 (the one that i plugin into plugin 1)
Now VLCObject implements VideoPlugin but when i use dynamic class loading in Plugin 1 to load VLCObject and cast it to VideoPlugin java gives an ClassCastException. The two VideoPlugin.java files are exactly the same proven by the fact that when i don't use the main application and directly launch Plugin 1 everything works fine.
I've also noticed that when i add the videoplugin directory to the main application everything works fine, but i don't really wanna do that.
After some further looking i've found that when i try to cast VLCObject to VideoPlugin in Plugin 1, the two VideoPlugin classes are not equal when i use the main application if i directly execute Plugin 1 they are equal
Do you possibly have two different versions of either VLCObject or VideoPlugin compiled in the different jar files?
No they are exactly the same, but after some digging today i've found the solution. The problem was that a different classloader was used to load the class then the original one. And thats why i couldn't cast an object from one jar to an object of another. I was able to solve this by just giving the current classloader to the constructor of the urlclassloader that loaded the classes from the other jars.