Results 1 to 3 of 3

Thread: Updating class

  1. #1
    dannycrafts is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Updating class

    Hello all,

    I'm trying to figure out how I can update (or reload) a class file during runtime. Instead of replacing the class file in the jar manually, I'd like to 'replace' it at runtime. This is what I got so far, even though it doesn't seem to actually do what I expect to see when it works:

    Java Code:
    URL url = getClass().getResource( "/com/dannycrafts/classes/ThreadLoginVerifier.class" );
    ClassLoader classLoader = URLClassLoader.newInstance( new URL[]{ url } );
    classLoader.loadClass( "net.minecraft.server.ThreadLoginVerifier" );
    As you can see is "/com/dannycrafts/classes/ThreadLoginVerifier.class" my own version of "net.minecraft.server.ThreadLoginVerifier".

    I would think that this would do the job, but I'm not quit sure if it does.

    Also, I am afraid that just a new version of the class is loaded and that everything that was using the class before is still using the old version.

    Can anyone help me with this if you know what I'm trying to achieve?
    Thanks.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Updating class

    I don't know of a way to replace a previously loaded class. If the JVM has links to the current version of a class, replacing the current version could break the system.
    Can you make your version available BEFORE the other version is loaded so your version is the one loaded?

  3. #3
    dannycrafts is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Re: Updating class

    Alright, I guess I just have to replace the class files manually. :)

Similar Threads

  1. Updating JDK
    By sandz24 in forum New To Java
    Replies: 4
    Last Post: 01-20-2012, 04:34 AM
  2. Updating the Instance Variable of a Class
    By Leo11221 in forum New To Java
    Replies: 19
    Last Post: 12-01-2011, 06:07 PM
  3. Updating a JLabel from another class.
    By Fumomo in forum AWT / Swing
    Replies: 6
    Last Post: 05-04-2011, 05:31 PM
  4. Updating my gui
    By mrx89_7 in forum New To Java
    Replies: 4
    Last Post: 02-09-2011, 06:33 AM
  5. Updating my GUI
    By Catkill in forum AWT / Swing
    Replies: 6
    Last Post: 09-01-2009, 06:09 PM

Posting Permissions

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