Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Self Updating Program [closed]

So, this is something that's been on my mind for a while now. How can you take a program, and make it 'auto-update'. So let's say an outer shell that checks Myserver.com/myProg/updates.xml (or some other resource) and checks to make sure version numbers are the same. Once I do that, how do I handle updating a program?

Let's say that my program was a simple main only class and the only output is:

System.out.println("Hello World"); On the update it turns into System.out.println("Hello Java");

How could I get this change into place at runtime?

Note: JNLP is not applicable for this, due to signing issues that I don't care to expand upon.

like image 997
A_Elric Avatar asked Nov 12 '12 18:11

A_Elric


2 Answers

If JNLP is ruled out, I'd think only a solution using OSGI would achieve that. Otherwise, even at the very simplest design possible, you'll need another program to manage and download the versions of your current program.

like image 33
javabeats Avatar answered Oct 28 '22 19:10

javabeats


You need 2 "applications":

  1. A minimal bootstrap application that checks for updates and runs the main application;
  2. The main application.

The user always launches the bootstrap application, never the main application (in fact the user doesn't know about the bootstrap application). This is by far the most common pattern I've seen.

If you want to do auto-updates at runtime, you'll need to use OSGI as javabeats mentioned. But only take this path if you really need this. I've never used OSGI, but I can imagine that it's non-trivial.

Edit

I don't have a concrete example, but I can imagine that

  1. the bootstrap downloads some jar and configuration files
  2. One of the configuration files contains the files required in the classpath (this could be done automatically by your app, if it picks all the jar files that are inside a given folder).
  3. With the previous list, create a new classloader (see example here) to add the jar files to the classpath.
  4. Run the main class of the application in the new classloader.

Sorry, I can't give you a more detailed answer without writing the code myself, but I charge for that :).

like image 83
Augusto Avatar answered Oct 28 '22 17:10

Augusto