简体   繁体   English

使用Java WebStart创建桌面应用程序的最佳实践

[英]Best practice for creating a desktop app using Java WebStart

Hope I can explain this clearly. 希望我能解释清楚。 I am creating a desktop application that has dependencies on other external jar files. 我正在创建一个依赖于其他外部jar文件的桌面应用程序。 For example, my application is Spring-based so there are some SpringFramework jar files that I will need in my application. 例如,我的应用程序是基于Spring的,因此我的应用程序中需要一些SpringFramework jar文件。

I am using Java WebStart to 'launch' this desktop application. 我正在使用Java WebStart“启动”此桌面应用程序。 (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. 但是,当我通过单击jnlp描述文件执行桌面应用程序时遇到麻烦。 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. 然后,我意识到我的桌面应用程序打包为JAR文件时,没有包含我的其他JAR依赖项。 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. 我猜想,我可以在桌面JAR文件中包含外部JAR依赖关系,但这会使我的桌面JAR文件很大。 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. 由于大的JAR文件,这将使我的JAR文件的下载变慢,因为单击JNLP描述符文件将始终从服务器的桌面JAR文件中获取资源。 (unless I can 'tell' the JNLP descriptor not to download if there is no new version on the server.) (除非服务器上没有新版本,除非我可以“告诉” JNLP描述符不下载。)

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. 无论如何,我在想这是否是一种可接受的方法,其中我的桌面JAR文件将不包括JAR依赖项,而仅包含对其的引用。 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. 当我的桌面应用程序启动时,它将检查这些依赖关系在桌面上是否可用,如果不可用,它将调用另一个JNLP描述符,该描述符将下载外部JAR文件并将它们复制到我的桌面的预定位置应用程序参考。 Will this work? 这样行吗? or is there a simpler solution to my problem? 还是有解决我的问题的简单方法?

thanks 谢谢

The JNLP file should include references to both your main file but also all needed libraries. JNLP文件应包括对您的主文件的引用,也应包括对所有所需库的引用。 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. 请注意,文件名中应带有时间戳,以避免更新代码时出现缓存问题。

You need to have your JNLP reference the additional jars you have. 您需要让您的JNLP引用您拥有的其他jar。 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. 是的,这将花费更长的时间下载,但是只要您不包括一堆不需要的jar,就不需要很长时间。 Web Start is smart enough to not re-download jars that have not changed on subsequent start ups of the same application. Web Start非常智能,无需重新下载在同一应用程序的后续启动中未更改的jar。 I have Java Web Start applications that have several large jars and this works just fine. 我有具有几个大罐子的Java Web Start应用程序,这很好用。

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. 如果您要这样做,那么使用Web Start没什么意义,您最好将整个程序安装在桌面上。

其他答案涵盖了大多数基础,但我想我应该补充一点,将多余的Jar标记为download ='lazy'可能是有意义的。

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

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