Updating running jar file

Discussion in 'Java' started by Grzesiek, Aug 12, 2007.

  1. Grzesiek

    Grzesiek Guest

    Hi,

    How to update a running jar file? I tried it that way:

    Here is my Update.class:

    import java.io.*;
    import java.util.*;
    import java.util.zip.*;
    import java.util.jar.*;

    public class Update {

    public static void main(String args[]) {
    System.out.println("Hello Mike");
    File oldFile = new File("appU.jar");
    File newJar = new File("appU1.jar");
    oldFile.delete();
    newJar.renameTo(origFile);
    }
    }

    Typing

    javac Update.java
    jar cfe appU.jar Update Update.class

    I also created appU1.jar file. appU.jar should update itself to
    appU1.jar while running appU.jar.
    But it doesnt work. Any ideas how to do it?

    Best regards,

    Grzesiek
    Grzesiek, Aug 12, 2007
    #1
    1. Advertising

  2. Grzesiek wrote:
    ...
    >Here is my Update.class:


    Is it?

    >import java.io.*;
    >import java.util.*;
    >import java.util.zip.*;
    >import java.util.jar.*;
    >
    >public class Update {
    >
    > public static void main(String args[]) {
    > System.out.println("Hello Mike");
    > File oldFile = new File("appU.jar");
    > File newJar = new File("appU1.jar");
    > oldFile.delete();
    > newJar.renameTo(origFile);
    > }
    >}
    >
    >Typing
    >
    >javac Update.java


    D:\Update.java:13: cannot find symbol
    symbol : variable origFile
    location: class Update
    newJar.renameTo(origFile);
    ^
    1 error

    Please post SSCCE's.
    <http://www.physci.org/codes/sscce.html>

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200708/1
    Andrew Thompson, Aug 12, 2007
    #2
    1. Advertising

  3. Grzesiek wrote:
    > Hi,
    >
    > How to update a running jar file? I tried it that way:
    >
    > Here is my Update.class:
    >
    > import java.io.*;
    > import java.util.*;
    > import java.util.zip.*;
    > import java.util.jar.*;
    >
    > public class Update {
    >
    > public static void main(String args[]) {
    > System.out.println("Hello Mike");
    > File oldFile = new File("appU.jar");
    > File newJar = new File("appU1.jar");
    > oldFile.delete();
    > newJar.renameTo(origFile);
    > }
    > }
    >
    > Typing
    >
    > javac Update.java
    > jar cfe appU.jar Update Update.class
    >
    > I also created appU1.jar file. appU.jar should update itself to
    > appU1.jar while running appU.jar.
    > But it doesnt work. Any ideas how to do it?


    1. What do you mean by "doesn't work"?
    2. What are you trying to accomplish?

    Any classes loaded from the jar won't be reloaded just because their
    definition changes on the disk. Also, it's quite possible that the class
    loader has kept the jar file open, which means that

    On Windows, you won't be allowed to delete the jar file
    On Unix-like systems, you'll be able to delete and replace it, but the
    class loader will still be reading from the old file until it's closed.

    It's also possible that the classloader closes the jar (to save open files
    on system where their number is limited) but keeps the file's index
    information in memory. Now replacing the jar file can lead to errors
    loading new classes, because they almost certainly begin at a different
    offset.
    Mike Schilling, Aug 12, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lucy
    Replies:
    6
    Views:
    30,616
    steve
    Sep 7, 2004
  2. Arnold Peters
    Replies:
    0
    Views:
    564
    Arnold Peters
    Jan 5, 2005
  3. muttley
    Replies:
    0
    Views:
    2,714
    muttley
    Oct 20, 2005
  4. cyberco
    Replies:
    4
    Views:
    3,748
    Roedy Green
    Feb 14, 2006
  5. Arnold Peters
    Replies:
    0
    Views:
    653
    Arnold Peters
    Jan 5, 2005
Loading...

Share This Page