使用 Java WebStart 创建桌面应用程序的最佳实践
希望我能清楚地解释这一点。我正在创建一个依赖于其他外部 jar 文件的桌面应用程序。例如,我的应用程序是基于 Spring 的,因此我的应用程序中需要一些 SpringFramework jar 文件。
我正在使用 Java WebStart 来“启动”这个桌面应用程序。 (至于我这样做的原因是我需要通过我们正在构建的网站执行这个定制的桌面应用程序)。
然而,当我通过单击 jnlp 描述文件来执行桌面应用程序时,我遇到了麻烦。它给出错误,指出我的桌面应用程序正在使用的某些类没有类定义。然后我意识到,当我的桌面应用程序打包为 JAR 文件时,它不包含我的其他 JAR 依赖项。这就是错误的原因。
我想,我可以在桌面 JAR 文件中包含外部 JAR 依赖项,但这会使我的桌面 JAR 文件变得相当大。由于 JAR 文件较大,这将使 JAR 文件的下载变慢,因为单击 JNLP 描述符文件将始终从服务器的桌面 JAR 文件获取资源。 (除非我可以“告诉”JNLP 描述符在服务器上没有新版本的情况下不要下载。)
无论如何,我在想这是否是一种可接受的方法,其中我的桌面 JAR 文件将不包含 JAR 依赖项,而只包含对它。当我的桌面应用程序启动时,它将检查这些依赖项在桌面上是否可用,如果不可用,它将调用另一个 JNLP 描述符,该描述符将下载外部 JAR 文件并将它们复制到我的桌面上的预定位置应用参考。这行得通吗?或者有更简单的解决方案来解决我的问题吗?
谢谢
Hope I can explain this clearly. I am creating a desktop application that has dependencies on other external jar files. For example, my application is Spring-based so there are some SpringFramework jar files that I will need in my application.
I am using Java WebStart to 'launch' this desktop application. (As to why I am doing this is that I need to execute this customised desktop application via the website that we are building).
However I ran into troubles when I executing my desktop application by clicking on the jnlp description file. It gives errors stating that there is no class definition for some of the classes that my desktop application is using. I then realise that my desktop application when packaged as a JAR file, it didnt include my other JAR dependencies with it. Hence the reason for the error.
I guess, I could include the external JAR dependencies in my desktop JAR file but this would make my desktop JAR file quite large. And this will be then make the download of my JAR file slow due to the large JAR file since clicking on the JNLP descriptor file will always source from the desktop JAR file from the server. (unless I can 'tell' the JNLP descriptor not to download if there is no new version on the server.)
Anyway, I was thinking if this is an acceptable approach where my desktop JAR file will not include the JAR dependencies but only references to it. When my desktop application launches, it will check if these dependencies are available on the desktop, and if it is not available, it will call another JNLP descriptor that will download the external JAR files and copy them to a pre-determined location that my desktop application references. Will this work? or is there a simpler solution to my problem?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
JNLP 文件应包含对主文件和所有所需库的引用。这是标准功能,您应该这样做。
请注意,文件名中应包含时间戳,以避免更新代码时出现缓存问题。
The JNLP file should include references to both your main file but also all needed libraries. This is standard functionality and you should do it that way.
Note that you should have a time stamp in your file names to avoid cache problems when updating code.
您需要让您的 JNLP 引用您拥有的其他 jar。是的,下载时间会稍长一些,但只要您不包含一堆不需要的罐子,这应该不会花费很长时间。 Web Start 足够智能,不会重新下载同一应用程序后续启动时未更改的 jar。我的 Java Web Start 应用程序有几个大 jar,这工作得很好。
至于将额外的罐子放在用户的机器上,我不建议这样做。如果您打算这样做,那么使用 Web Start 就没有多大意义,您还不如将整个程序安装在桌面上。
You need to have your JNLP reference the additional jars you have. Yes this will take slightly longer to download, but as long as you are not including a bunch of jars that you don't need this should not take very long. Web Start is smart enough to not re-download jars that have not changed on subsequent start ups of the same application. I have Java Web Start applications that have several large jars and this works just fine.
As far as putting the extra jars on the user's machine, I would not advise this. If you are going to do that, then there is not much of a point to use Web Start and you might as well install the entire program on the desktop.
其他答案涵盖了大多数基础,但我想我应该补充一点,将额外的罐子标记为 download='lazy' 可能是有意义的。
The other answers covered most bases, but just thought I should add that it might make sense to mark the extra Jars as download='lazy'.