下载远程jar文件并监控下载进度
我是 Java 新手(我有 ActionScript 背景),我想知道是否有一种方法可以下载并监视小程序内远程 jar 文件的下载进度,然后使用其中的类和其他资源下载的罐子。 我知道有一个 JarURLConnection 类,但我找不到通过该类监视下载进度的方法。
我需要这样做的原因是因为我试图将 JavaFX 小程序分成多个模块,以便按需下载。
I'm new to Java (I come from an ActionScript background) and I'd like to know if there's a way to download and monitor the download progress of remote jar files inside an applet, then use the classes and other resources that are inside the downloaded jar. I know there's a JarURLConnection class, but I could not find a way to monitor the download progress through this class.
The reason why I need to do this is because I'm trying to make a JavaFX applet divided into modules, downloadable on demand.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下载所有 Jar 文件的默认行为通常是可以接受的,它会下载并显示进度条,但听起来您需要将东西分开。 AFAIK,如果不签署您的小程序,则无法手动下载类并添加到类路径(或自定义类加载器),这是我猜您不想遵循的路径。
您可能想看看 延迟下载,自 Java 1.6 update 10 起可用。
在不知道您的确切要求的情况下,我对如何拆分它的一般建议是下载初始 Jar 中的所有类文件并根据需要下载资源(图像/声音/属性) 。
如何从小程序中下载的代码:
The default behaviour downloading all Jar files is usually acceptable, it downloads and shows a progress bar, but it sounds like you have a requirement to split things up. AFAIK, manually downloading classes and adding to a classpath (or custom class loaders) can't be done without signing your applet which is a path I guess you don't want to follow.
You might want to take a look at lazy downloading, available since Java 1.6 update 10.
Without knowing your exact requirements, my general advice on how you could split it would be to download all class files in the initial Jar and download resources (images / sounds / properties) as required.
Code for how to download from within an applet:
您可以定义自定义
ClassLoader
并将其用于您的远程模块。 这将使您能够准确控制类字节如何传输到您的小程序。 如果您想一次加载整个 JAR 文件,您可以让自定义类加载器在需要时下载 JAR 文件,并使用JarInputStream
。You could define a custom
ClassLoader
and use this for your remote modules. This will let you control exactly how the class bytes are transferred to your applet. If you want to load entire JAR files at a time, you could make your custom class loader download JAR files when needed and unpack them withJarInputStream
.