简体   繁体   English

Java Swing桌面应用程序中的自动更新功能

[英]Autoupdate feature in a Java Swing desktop App

I've developed a desktop Swing app and I'm thinking about the best way to provide the autoupdate feature. 我开发了一个桌面Swing应用程序,我正在考虑提供自动更新功能的最佳方法。 I know that JavaWebStart provides this but I think that It doesn't suit my needs because I need to read local files so I would need to sign the jar. 我知道JavaWebStart提供了这个,但我认为它不适合我的需要,因为我需要读取本地文件,所以我需要签署jar。 Besides, JWS requires extra work to deploy in the server while now I only need to upload the .jar. 此外,JWS需要额外的工作才能在服务器中部署,而现在我只需要上传.jar。

I've been thinking about this approach: 我一直在考虑这种方法:

  • A first JAR (which never needs updating) loads the splashscreen, checks the current version in a config.xml and compares it to the server config.xml. 第一个JAR(永远不需要更新)加载启动画面,检查config.xml中的当前版本并将其与服务器config.xml进行比较。

  • If server version is newer, ask the user whether he wants to update. 如果服务器版本较新,请询问用户是否要更新。 In that case, download the new "main.jar", the new "config.xml" and the new splash/icon, check MD5SUM, and replace the old files with the new ones. 在这种情况下,下载新的“main.jar”,新的“config.xml”和新的splash / icon,检查MD5SUM,并用新的文件替换旧文件。

  • Launch "main.jar". 启动“main.jar”。

I don't know If I'm trying to reinvent the wheel or If there's a better pattern than the one I've put above. 我不知道如果我正在尝试重新发明轮子,或者如果有一个比我上面提到的更好的模式。

We did a similar thing. 我们做了类似的事情。 We just got it via https and downloaded the jar. 我们刚刚通过https获取并下载了jar。 To know if you need a new one we just check the size on the stream. 要知道您是否需要新的,我们只需检查流上的大小。 Theoretically that may not work, but in practice it did. 理论上可能不起作用,但实际上它确实有效。 We got even fancier by getting the directory listing where the jars were located, parsing it and downloading each jar, so the name of the jar wasn't hard coded either. 通过获取jar所在的目录列表,解析它并下载每个jar,我们甚至变得更加漂亮,因此jar的名称也没有硬编码。 There are a couple of ugly points, though. 但是有一些丑陋的观点。

First was launching a new jvm process to start the new jar is a not so simple. 首先是启动一个新的jvm进程来启动新的jar是不是那么简单。

Second, you have to be sure you don't corrupt your jar if your update fails in the middle. 其次,如果您的更新在中间失败,您必须确保不会破坏您的jar。

Finally, there is no way to update the bootstraping jar with this process. 最后,没有办法用这个过程更新bootstraping jar。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM