Results 1 to 3 of 3
  1. #1
    dieter1990 is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Default 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.

    Main application
    -launcher
    *Launchable.class
    *LaunchWindow.class
    -....

    Plugin 1 (the one that i plugin into the main application)
    -launcher
    *Launchable.class
    -videoplugin
    *EpisodeLocator.class
    *VideoPlugin.class
    -....

    Plugin 2 (the one that i plugin into plugin 1)
    -videoplugin
    *EpisodeLocator.class
    *VideoPlugin.class
    -vlcplugin
    *VLCObject.class
    *....

    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
    Last edited by dieter1990; 08-25-2010 at 08:22 PM.

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Do you possibly have two different versions of either VLCObject or VideoPlugin compiled in the different jar files?

  3. #3
    dieter1990 is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Default

    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.

Similar Threads

  1. Dynamic image loading in jsp
    By ramakrishna k m in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 10-10-2011, 07:08 AM
  2. After loading class, how to run it?
    By crikey in forum Advanced Java
    Replies: 19
    Last Post: 08-25-2010, 11:44 PM
  3. Replies: 8
    Last Post: 04-14-2010, 06:49 AM
  4. Dynamic Class Loading from external Jar
    By AndreB in forum Advanced Java
    Replies: 3
    Last Post: 02-08-2010, 02:55 PM
  5. class loading
    By purejoker in forum AWT / Swing
    Replies: 1
    Last Post: 01-20-2009, 01:09 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •