0

For my program I would like to check for a new update when it is run. I don't want it to auto update. It doesn't even need to provide a link to a new version.

I was thinking that how I should do it is, I should have a webpage like:

www.website.com/checkversion

The page would contain just 1 thing. It would contain a version number. The version number on the site would be the latest version that is released. If the version number is not equal to the one of the program it would make the user aware that there is a newer version. Else it would of course do nothing.

I have looked at this question: Automatically checking for a new version of my application , and I it got me thinking. Is this the way I should be doing it? I'm not sure if doing it this way will provide me with enough ground you could say to give enough information.

I'm wondering which approach I should use and what sort of functions I would need to use as I have not played around with web based functions before.

Community
  • 1
  • 1
ComputerLocus
  • 2,779
  • 9
  • 41
  • 80
  • Using [Java Web Start](http://stackoverflow.com/tags/java-web-start/info), update is configurable in the JNLP files, and can be taken under programmatic control. f course, if you insist on reinventing existing technology, go for it. I expect a programmer experienced in web-tech. & Java could produce a workable solution in maybe 2-3 months. *"I have not played around with web based functions before."* Oh, triple that estimate. :( – Andrew Thompson Apr 13 '12 at 07:34

1 Answers1

1

As a general idea, this is pretty much what you have, I would recommend to return not just a number, but instead some dictionary/map, serialized as JSON or similar, so maybe in the future you would like to put more data, and still be compatible with old versions. For example, instead of returning :

1

return:

{"latest_version" : 5}

So if you want to add more details in the future, you may return:

{"latest_version" : 5, "minimal_compatible_version" : 2, "download_file_size_in_bytes" : 123456 }

The idea is to let the response expand (when you need to return more data) and still be backward compatible.

As for how to perform such a request, take a look here (although apache commons has a great library as well).

Community
  • 1
  • 1
MByD
  • 129,681
  • 25
  • 254
  • 263
  • Sorry I'm a littler newer to Java here. Would you be able to maybe explain this in a little more detail, to help me understand? – ComputerLocus Apr 13 '12 at 01:40
  • Okay I understand how I am suppose to get the data now from a site, but I am still lacking the understanding of how I would exactly parse the data and know what the data means. So in the example you provided how would the program parse that data out. I'm assuming it's related to JSON but unfortunately I'm not experienced enough to understand this fully. – ComputerLocus Apr 13 '12 at 01:56
  • Take a look at this question: http://stackoverflow.com/questions/338586/a-better-java-json-library – MByD Apr 13 '12 at 02:00
  • Well if you take a look here: http://code.fogest.net16.net/version.html is that what the page should look like or do I have this all wrong? – ComputerLocus Apr 13 '12 at 02:17
  • Okay so I got it down for the web part and for the fetching it, now I just need to know how to take a string like that and read it in and use that. Are there any good examples of someone reading in a line like that and using it? I'm sure it's not hard once I understand it. – ComputerLocus Apr 13 '12 at 02:20
  • It really isn't take a look here: http://stackoverflow.com/questions/1359689/how-to-send-http-request-in-java – MByD Apr 13 '12 at 02:21
  • Yes but aren't these answers just showing how to read from the site? Not how to take a string like `{"latest_version" : 5, "minimal_compatible_version" : 2, "download_file_size_in_bytes" : 123456 }` and separate the content. – ComputerLocus Apr 13 '12 at 02:25
  • OK, I misunderstood you. Take a look at this tutorial: http://viralpatel.net/blogs/2009/02/creating-parsing-json-data-with-java-servlet-struts-jsp-json.html – MByD Apr 13 '12 at 02:28
  • Little problem. The condition that this program is I can not really use extra libraries. It's essentially a mod for a game and I can not have extra files. I guess I will stick with checking the version the way I stated. I guess technically I could have it read 1 line for a version. If I decide to add more I have the new ones read more lines on the page. Therefore the new lines will not be read by the old one anyway. Thanks for the help! – ComputerLocus Apr 13 '12 at 02:34
  • The idea is the same, it doesn't have to be JSON, it may be simply "version=1.2\n minimal_compatible_version=2" and the parsing may be simpler, JSON is much more powerful though... – MByD Apr 13 '12 at 02:36