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
Andrew Thompson - 12 Aug 2007 13:31 GMT
...
>Here is my Update.class:
Is it?
>import java.io.*;
>import java.util.*;
[quoted text clipped - 15 lines]
>
>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>

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Mike Schilling - 12 Aug 2007 19:54 GMT
> Hi,
>
[quoted text clipped - 26 lines]
> 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.