Pergunta

  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?

Foi útil?

Solução

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.

Outras dicas

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.)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top