4

I am faced with an issue of implementing an autoupdate feature into a desktop JavaFX application. I'm not sure if it makes a difference - but it's going to be run by double-clicking the .jar file and will have a GUI representation, obviously.

Now to the problem:

I need to perform an autoupdate upon the app's execution - this means syncing with a server and checking if an update is available: if so, then download the new version and reload the current one.

I'm not very familiar with any optimal approaches to this issue. This is what I need to solve, as it seems:

A - somehow download to the same location where the currently ran file resides with the same file name (AFAIK Windows deliberately places a block on every running file / process - claiming for it to be in use)

B - figure out a way how to launch a new process within this application that won't die upon its termination (in order to reload the new v.)

I figure B can be manipulated differently - anyway, the end result is that I must have the same file name in the same directory, as the initially launched app.

I guess even more complexity is added due to the fact that this should be multiplatform capable - Windows + MacOSX. Anyhow, I would be grateful to see suggestions even relative to only one of the OSs in question.

XXL
  • 1,224
  • 4
  • 12
  • 25
  • for a, you could rename the running app and download the new version with the right name. – 11684 Apr 27 '12 at 22:18
  • @11684 right, but how would I do that on a running process (in Windows)? – XXL Apr 27 '12 at 22:19
  • good point. Perhaps some shell-script that gets run BEFORE the new actual app gets installed? I didn't think very well about my comment before i posted it. – 11684 Apr 27 '12 at 22:40
  • Over the last few days, I built a (basic) pure Java solution to solve auto-updating. Not sure it runs with JavaFX if your requirements include updating FX itself, but it shows how one might address the issue: https://github.com/UrsKR/updates-r-simple – Urs Reupke Aug 01 '12 at 08:48

1 Answers1

6

Don't bother reimplementing an issue that's been resolved for java before. It's called Java Web Start. It does exactly what you need. It's even multi platform!

Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
  • Hmm, bear with me, does this mean that it will only work within a browser? – XXL Apr 27 '12 at 22:24
  • No, it also works with a Desktop Application. You will double click your JAR file, it will launch JWS (Java Web Start) and will update the application if needed. Otherwise, it'll just run the application. I am telling you: it's **exactly** what you are looking for. – Pablo Santa Cruz Apr 27 '12 at 22:26
  • I am somewhat struggling to find a guide / tut for what you have described. Any links, really? Most of the one's I've found are either already obsolete or discuss the JWS inside a web browser. – XXL Apr 28 '12 at 09:21
  • "Web Start Mode. The application is generally initiated from a web page link, but the application itself runs outside the browser on the desktop." - as seen here: http://docs.oracle.com/javafx/2/get_started/basic_deployment.htm I noticed the world "generally", so I guess there's another way and apparently that's what you are stating in your post. Um, so any info on how I could do this alt. version? Pretty much what's mentioned on that link refers to running a .jnlp file, but not having .jar as the point of entry. – XXL Apr 28 '12 at 11:53
  • 1
    @XXL: try running a very simple JNLP file. You'll see what's JWS about. Here's a tutorial: http://download.oracle.com/javase/tutorial/deployment/webstart/ – Pablo Santa Cruz Apr 28 '12 at 12:07
  • I have already tried running this: http://portecle.sourceforge.net/ My question still remains though - is it possible to have a .jar as an entry point for JWS in regards to JavaFX? I can see that all of the examples are strictly .jnlp based.. – XXL Apr 28 '12 at 12:10
  • JNLP file will be downloaded to your computer. Next time you want to run the application, you don't need to point to the WEB-SERVER. You just need to double click the JNLP file (just as if you'd click a JAR file). – Pablo Santa Cruz Apr 28 '12 at 12:25
  • If you tried that PORTECLE application, you'll that after launching it, it "installs" into your computer. Next time it runs, first thing it does is check if there's a new version for update. – Pablo Santa Cruz Apr 28 '12 at 12:28
  • I see. So there is no way to make the .jar as the entry point for JWS then? That kind of contradicts what you've said earlier "No, it also works with a Desktop Application. You will double click your JAR file, it will launch JWS (Java Web Start) and will update the application if needed. Otherwise, it'll just run the application. I am telling you: it's exactly what you are looking for.". Well, I guess I will have to work with what's available then (.jnlp).. Thanks. – XXL Apr 28 '12 at 12:57
  • @XXL: right. I shouldn't have said "double click your JAR file". But your entry point is an icon, on your desktop, so I guess the end result is the same. Good luck! You won't regret using JWS. It's pretty good. It's even clever when selecting "WHAT" to update. That's it: if you only update one library in your application (a JAR), then it will just get that one and only library instead of downloading the whole application again. – Pablo Santa Cruz Apr 28 '12 at 13:07
  • Good to hear and thanks again. One last question - how would one evade the this type of security warning: http://i.imgur.com/XH11e.png (occurs when running PORTACLE). Can code signing help in this case? And what are the requirements in order to have a valid publisher? – XXL Apr 28 '12 at 13:16
  • 1
    See also the [info. page on JWS](http://stackoverflow.com/tags/java-web-start/info) for lots of useful links. – Andrew Thompson Apr 28 '12 at 21:54
  • 1
    Note that JavaFX apps won't be deployable via Web Start on Mac OS X until the JDK7u6 release ([reference](https://blogs.oracle.com/henrik/entry/oracle_jdk_and_javafx_sdk) and [release notes](http://docs.oracle.com/javafx/2/release_notes_2-1/jfxpub-release_notes_2-1.htm)). – jewelsea Apr 30 '12 at 17:13