UpdaterAPI is a useful Java API for creating a simple Auto-Updater. Its downloading a jar file from a custom url and replace it.
How it works:
- Implement the UpdaterAPI class in your Java program (See here)
- After starting your Java program it will download the Updater (See here)
- Your program starts the downloaded Updater jar before its closing (See here)
- The Updater downloading the newest Jar from your Website
- The Updater replaces the new Jar with the old
- And done!
Here we use the UpdaterAPI class. You need to implement this class in your Java program. The UpdaterAPI uses the Gson & the Apache-Commons-IO library's. These librarys you must implement too in your program
public void start() {
UpdaterAPI.downloadUpdater(new File("./Updater.jar"));
}
public void update() {
File newFile = new File("./YourProgram.jar");
String url = "www.yoururl.com/api/yourprogram/v1.0/YourProgram.jar";
try {
UpdaterAPI.update(url, newFile);
} catch (IOException e) {
e.printStackTrace();
}
}
- Use
UpdaterAPI.setAutoDelete(true)
that the Updater is only available in the directory, when the program has a new version to update. Default is that the updater is always available in the folder.
- This parameter is the url from where the Updater downloads the latest file of your program. (for example: www.yoururl.com/api/yourprogram/v1.0/YourProgram.jar)
- Your file of the program what you want to replace (Must be a absoult path)
- The new Path location of your program what you want to replace (Must be a absoult path)
- (Optional) With the 4. parameter you can restart the jar file