0

I have a jar which is deployed and then executed on some machine. When the process ends, I would like to delete that jar automatically. What is a best way to do so? Can a jar delete itself when the process exits?

Tad
  • 838
  • 2
  • 11
  • 22
  • Couldn't you just find the directory of the jar internally, then delete it? Possibly inside a finalize method. – Carcigenicate Jun 29 '15 at 19:00
  • but how can finalize method delete a jar which contains that finalize method? – Tad Jun 29 '15 at 19:44
  • Also, there are hundreds of jars uploaded there so I can't just get the directory. the process is: jar gets uploaded, executed, then i want it to be deleted – Tad Jun 29 '15 at 19:45
  • I've never done it in Java, but there should be a way to get the path to the current process. And wouldn't the jar be for the most part in the RAM by that point? You may get a error saying that the resource is in use, but I'm sure there's a way around that. – Carcigenicate Jun 29 '15 at 19:48
  • http://stackoverflow.com/questions/320542/how-to-get-the-path-of-a-running-jar-file – Carcigenicate Jun 29 '15 at 19:50
  • http://stackoverflow.com/questions/28418807/how-to-delete-the-executable-jar-file-by-it-self Looks like on Windows, a jar can't be deleted of it's currently being used by the JVM. You could have a separate clean up program that feels with this. – Carcigenicate Jun 29 '15 at 19:54
  • See my answer to this question: http://stackoverflow.com/questions/28418807/how-to-delete-the-executable-jar-file-by-it-self?noredirect=1&lq=1 – regev avraham Nov 28 '16 at 21:56

0 Answers0