aspose file tools*
The moose likes Java in General and the fly likes issues with updating jar files which are being used in a program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "issues with updating jar files which are being used in a program" Watch "issues with updating jar files which are being used in a program" New topic
Author

issues with updating jar files which are being used in a program

reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
I'm trying to create some feature that the program will do automatic updates for itself.

The program uses some jar file while running. During the run time, I let the program download an updated jar file at some point, with different name, say, append a '_TMP' at the end, which is to avoid directly overwriting the current used jar file, which will cause the program to freeze forever.

Next, I created a prompt message box, at some point, ask users if they want to update and restart the program, if yes, (1) the program will shut down, (2) do the update (delete old jar file, rename jar file with '_TMP' back to the original name), and (3) start the program again.

These 3 steps are what I planned to do. But when I implement it, I always either not be able to restart the program, (3), or not be able to modify jar files (2).

I let step (3) to be in a separate Thread class, but it seems as long as the Main class, program itself, is turn off, by using appExitListener.windowClosing(null); and System.exit(0); No child threads would continue working.

If I'm not using a separate Thread to do step (3), step (2) will always fail, by saying, the jar file is failed to delete or rename, as I think it's still being used the program.

Please help how to implement these steps 1, 2, 3. Thanks.


SCJA, SCJP5.0, SCBCD, SCWCD
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Launch an entirely separate program to rename the file and re-launch the first program.


[Jess in Action][AskingGoodQuestions]
reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
I tried to use batch file to do rename and re-launch the program, but still not working ...

Here is my batch file:
--------------------------------------------------
If Exist "base.jar_NEW" (
REN "base.jar" "base.jar_OLD"

REN "base.jar_NEW" "base.jar"

)

START "" "Service.exe"
--------------------------------------------------
Now, the batch is able to re-launch the program Service.exe, but base.jar and base.jar_NEW are not getting renamed. If I run the batch file alone, it is able to rename them.

I guess while the batch file is running, the program is not shutting down completely, which still uses base.jar and prevent other things modify it. So I put 'TIMEOUT 5' in front of the batch file, but it still does not make anything better... Batch file seems not getting delayed for 5 sec either if calling from Java program... (My batch file works perfect if running alone.)

Please help. Thanks.


reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
I think the problem is about, the batch file has to be delayed for a few seconds, which is after the main program is shut down. Then do the change on the jar file. But it seems TIMEOUT 5, is not working if calling by the Java program. Although it works if I just double click to make it running.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: issues with updating jar files which are being used in a program