[英]Downloading JAR files at runtime in Java
I am wondering if it is possible to have a Java desktop application, on startup, look to some URL, to see if it needs an update, and if so download necessary JAR files, and add them to classpath for the running program. 我想知道是否可以在启动时使用Java桌面应用程序,查看某个URL,查看是否需要更新,如果是,则下载必要的JAR文件,并将它们添加到运行程序的类路径中。
If the old jars are there, they shouldn't have been loaded into the classloader yet, at this point should they? 如果旧的罐子在那里,它们不应该已经加载到类加载器中,此时应该是吗? Is it possible to swap them out before they are loaded w/out restarting the application? 是否可以在加载w / out重启应用程序之前将它们换掉?
JNLP ( Java Web Start )将为您完成所有这些工作 。
It should be possible. 它应该是可能的。 The URLClassLoader is a place to start. URLClassLoader是一个开始的地方。
It's possible but prone to error. 它可能但容易出错。
A somewhat cleaner approach is to have a "launcher" application which does not rely on any of the updatable JARs do the above and then launch the actual app. 一种更简洁的方法是拥有一个“启动器”应用程序,它不依赖任何可更新的JAR执行上述操作,然后启动实际应用程序。
You may want to check out this question for more details on this topic. 您可能需要查看此问题以获取有关此主题的更多详细信息。
Java Web Start is probably your best bet. Java Web Start可能是您最好的选择。 The required jar files should be identified in the descriptor allowing your to manage the version control. 应在描述符中标识所需的jar文件,以便管理版本控制。
If you have a dynamic application that needs to discover and download classes dynamically at runtime, then you could look at Dynamic code downloading using RMI . 如果您有一个动态应用程序需要在运行时动态发现和下载类,那么您可以使用RMI查看动态代码下载 。
Java Web Start is a good choice but has some quirks. Java Web Start是一个不错的选择但有一些怪癖。 Notably: 值得注意的是:
But WHEN it works it works pretty well. 但是当它工作时它的效果非常好。 It is to my knowledge the easiest way to have a centralized version easily updateable of a given Java application. 据我所知,让集中式版本可以轻松更新给定Java应用程序的最简单方法。
-- -
EDIT: It appears that the "start program and transparently download updates if available" functionality is present in the latest Java 6. I have not tried it yet, but will soon. 编辑:最新的Java 6中似乎存在“启动程序并透明地下载更新(如果可用)”功能。我还没有尝试过,但很快就会尝试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.