Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

Updating running jar file

Thread view: 
Grzesiek - 12 Aug 2007 10:23 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.