0
  1. check server for a directory containing updates.
  2. download the jars to current application directory.
  3. notify user to restart app.

My concern is with overwriting the old files while the java application is running.

for example myapp.jar and other library jar has been updated and needs to be replaced by downloading the new versions into the current application directory and overwriting it in the process. Is there a way to achieve this? Will it allow overwriting?

KJW
  • 15,035
  • 47
  • 137
  • 243
  • 3
    I don't see how this question is substantively different from your earlier question that I voted to close. Voting to close this one. – Andrew Thompson Dec 03 '11 at 04:59
  • need some explanation why this needs to be closed. how is my question any different from http://stackoverflow.com/questions/4706153/how-to-write-a-self-updating-program-in-java ? – KJW Dec 03 '11 at 05:14
  • That question does not rule out the **obvious** answer of using JWS(1). I feel you have been too quick to dismiss JWS. Of course, that is the reason why *I* chose to flag the questions for close, I cannot speak for anyone else. 1) In fact, the *[accepted answer](http://stackoverflow.com/a/4706165/418556)* boils down to *"Use JWS"*. – Andrew Thompson Dec 03 '11 at 05:16
  • well I have used JWS before and it has had too much problems, and that is why I need a non JWS solution to update my application. I hardly think theres a rule on SO that forces the use of the awful JWS. – KJW Dec 03 '11 at 05:20
  • *"I have used JWS before and it has had too much problems"* Until you prove differently, I figure that is because the launch files are "too much broken". I wrote [JaNeLA](http://pscode.org/janela/) to help verify JWS launches. Once the red errors identified by JaNeLA are fixed, most deployments come good. – Andrew Thompson Dec 03 '11 at 05:23
  • I never asked for a JWS solution. I was looking at ways to employ non JWS solution. I don't see why this is so difficult for you to accept. – KJW Dec 03 '11 at 05:29
  • 2
    (shrugs) Good luck with reinventing (a small part of what) JWS (can do already). – Andrew Thompson Dec 03 '11 at 05:34
  • I know it can but it doesn't do it very reliably I'm afraid for my needs and based on my experience and reading other problems people listed with using JWS, I will probably not pursue it any further. – KJW Dec 03 '11 at 05:43
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/5544/discussion-between-kim-jong-woo-and-andrew-thompson) – KJW Dec 03 '11 at 05:53

2 Answers2

2

Is there a way to achieve this?

I expect so. But its your job to make it work. And seriously, the consensus is that you are reinventing the wheel.

Will it allow overwriting?

You can't rely on being able to overwrite a JAR file that is in use because you are currently executing it.

There are various ways (*) you could work around this, but they boil down to having some kind of custom launcher that takes care of the downloading, updating and so on ... and then launches or relaunches your real application. And, basically, this is what JNLP does ... hence the observation that you are proposing to reinvent the wheel.

(* I'd add, that these ways are pretty obvious to me. And if they are not obvious to you, that's another reason why you'd be better of just using JNLP. Otherwise you risk ending up with a square wheel.)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
1

You can't count on being able to overwrite jar files. It will probably work on Linux, but definitely not on Windows.

One way to solve this is to download the jars to a temporary location, and then when you start (before the JVM starts) move the temp jars to the app download location and then start. Note: you will want to verify the contents of the jars somehow after download to make sure they're not corrupt. An md5sum will work.

BillRobertson42
  • 12,602
  • 4
  • 40
  • 57
  • how can I go about moving the temp jars to the app location if the JVM hasn't started? – KJW Dec 03 '11 at 05:46
  • Script, executable, another JVM running on a different Jar. There are lots of ways. – BillRobertson42 Dec 03 '11 at 06:32
  • so I plan on doing something like creating a separate updater.jar and run that from myapp.jar. if update is detected, it will ask to close myapp.jar and proceed to download and update the files as needed. – KJW Dec 03 '11 at 07:24