0

How can I find the Jar File that my Program is running from, when it is being packed using jpackage (as a URI, URL or File)? I could easily do this on Windows because I know where it is going to be installed, but I would like to make this work on all platforms (Windows, Linux and MacOS). I am unable to experiment with this since I don't have a Mac nor a Linux Machine.

I want to be able to update my Application before/after starting it.

Thanks!

  • I sense an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem/66378#66378). Why do you need this? – VGR Jun 15 '21 at 22:03
  • 1
    I am trying to Update the Client every Time I start or stop it. Sorry for not telling that. – MCPfannkuchen Jun 16 '21 at 06:24
  • Do you mean something like [Java Web Start](https://docs.oracle.com/javase/8/docs/technotes/guides/javaws/)? Each time you launch the client, it checks whether there has been an update since the last launch. – Abra Jun 16 '21 at 06:35
  • 2
    It’s implementation specific, but usually, you can’t overwrite the jar file while it is running. – Holger Jun 16 '21 at 08:21
  • 1
    Ah okay, I am not searching for anything like Web Start (which has been abandoned in jdk 9), but just replacing the jar. btw, for some reason you cannot delete a File nor rename it, but overwriting it while it runs works fine. The thing is that it is located in Program Files on Windows, and I do not know how to ask for UAC without starting a seperate Program. – MCPfannkuchen Jun 16 '21 at 08:55
  • I wasn't suggesting that you use Java Web Start. I was asking if what you want to do is similar to the way Java Web Start works. In other words, when you launch your application, the application itself checks whether there was an update since the last time that it was launched and if there was, then the application updates itself. Like [Notepad++](https://notepad-plus-plus.org/). When you run it, a window may pop up saying that there is a new version and asking you if you want to install the new version. Is that what you are trying to do? – Abra Jun 16 '21 at 09:13
  • Yes that is what I am trying to do. But I want to be able to update the JVM as well, in case I add new dependencies (which are being bundled using modules) – MCPfannkuchen Jun 16 '21 at 11:24
  • In that case, I would recommend you to add information about the version in the JAR itself and completely reinstall the program if it differs. – dan1st Jun 16 '21 at 11:32
  • That sounds like a good Idea, how would I do it though, because JPackage installer complains about the Program Already being installed. – MCPfannkuchen Jun 16 '21 at 11:57
  • Come to think of it, don’t most installers do the same thing when the program is already installed? – VGR Jun 16 '21 at 13:22
  • Yeah they do, I guess I'll have to find some hacky way to force it. – MCPfannkuchen Jun 21 '21 at 15:22

0 Answers0