Updating running jar file

G

Grzesiek

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
 
A

Andrew Thompson

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
 
M

Mike Schilling

Grzesiek said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top