Java Swing桌面应用程序中的自动更新功能 [英] Autoupdate feature in a Java Swing desktop App

查看:1052
本文介绍了Java Swing桌面应用程序中的自动更新功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个桌面Swing应用程序,我正在考虑提供自动更新功能的最佳方法。
我知道JavaWebStart提供了这个,但我认为它不适合我的需要因为我需要读取本地文件所以我需要签署jar。此外,JWS需要额外的工作才能在服务器中部署,而现在我只需要上传.jar。

I've developed a desktop Swing app and I'm thinking about the best way to provide the autoupdate feature. 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. Besides, JWS requires extra work to deploy in the server while now I only need to upload the .jar.

我一直在考虑这种方法:

I've been thinking about this approach:


  • 第一个JAR(永远不需要更新)加载启动画面,检查config.xml中的当前版本并将其与服务器配置进行比较.XML。

  • 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.

如果服务器版本较新,请询问用户是否要更新。在这种情况下,下载新的main.jar,新的config.xml和新的splash / icon,检查MD5SUM,并用新的文件替换旧文件。

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。

Launch "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.

推荐答案

我们做了类似的事情。我们刚刚通过https获取并下载了jar。要知道您是否需要新的,我们只需检查流上的大小。理论上可能不起作用,但实际上它确实有效。通过获取jar所在的目录列表,解析它并下载每个jar,我们甚至变得更加漂亮,因此jar的名称也没有硬编码。但是有一些丑陋的观点。

We did a similar thing. We just got it via https and downloaded the 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. There are a couple of ugly points, though.

首先启动一个新的jvm进程来启动新的jar是不是那么简单。

First was launching a new jvm process to start the new jar is a not so simple.

其次,如果您的更新在中间失败,您必须确保不会破坏您的jar。

Second, you have to be sure you don't corrupt your jar if your update fails in the middle.

最后,没有用这个过程更新bootstraping jar的方法。

Finally, there is no way to update the bootstraping jar with this process.

这篇关于Java Swing桌面应用程序中的自动更新功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆