Sometimes ourProgramYou need to connect to the server to detect the new version. If you find the new version, you need to automatically download and upgrade it. But in windows, how can I replace a running program file?
Of course there is a way, the steps are as follows:
1. Package and release our program using Java program proxy (here we need to use its advanced version instead of the free version, click to download)
2. The program runs normally. Connect to the server and check the new version.
3. When a new version is found, download the new version file from the server (generally a jar package) to the folder where the program is located, and add ". Update" as the file extension.
4. prompt the user to restart
This completes the online upgrade process.
The above steps may be abstract. Here is an example:
Suppose our program is packaged into "program. jar ", the new version is found on the server during running, so we need to download the new version of" program. jar, and name it "program. jar. update, and then prompt the user to restart the program.
What if the third-party jar package dependent on our program lock needs to be upgraded? Similarly, download the new jar version to the same directory as the old jar version and name it "XXX. Update.
Of course, the program may fail to be upgraded, or the version may need to be rolled back for other reasons. How can this problem be solved?
During the upgrade of Java program proxy, the old program file has been renamed as "XXX. Bak ". What to do next is obvious: Rename "XXX. Bak" to "XXX. Update" and prompt the user to restart the program.