简体   繁体   English

如何从 Java 应用程序更新 JRE(或运行时映像)?

[英]How do I update my JRE (or Runtime Image) from my Java application?

I have an application that consists of a JRE (or custom runtime image, as the jlink docs call it), a JAR file, and a method to run the JAR on the JRE (either a bash or batch file or an exe or .app package).我有一个应用程序,它包含一个 JRE(或自定义运行时映像,如 jlink 文档所称)、一个 JAR 文件和一个在 JRE 上运行 JAR 的方法(bash 或批处理文件或 exe 或 .app包裹)。

I want to send out updates for the application (which is working, I can connect to my server and download newJRE.zip and newJAR.jar), but I don't know the best way to replace the currently running JRE with the new JRE.我想发送应用程序的更新(它正在运行,我可以连接到我的服务器并下载 newJRE.zip 和 newJAR.jar),但我不知道用新的 JRE 替换当前运行的 JRE 的最佳方法.

I've tried unzipping the new JRE to a seperate folder, using ProcessBuilder to restart my JAR on the new JRE, then calling System.exit() on the original JRE and from the new JRE deleting the old JRE and copying the new JRE to the original location, and finally restarting my app again on that JRE.我尝试将新 JRE 解压缩到一个单独的文件夹,使用 ProcessBuilder 在新 JRE 上重新启动我的 JAR,然后在原始 JRE 上调用 System.exit() 并从新 JRE 删除旧 JRE 并将新 JRE 复制到原始位置,最后在该 JRE 上再次重新启动我的应用程序。 That didn't work (on Windows, I haven't tried yet on Linux or Mac) because the new, restarted JRE appears to be holding file locks (or handles?) on some of the files in the old JRE, so it can't delete them.这不起作用(在 Windows 上,我还没有在 Linux 或 Mac 上尝试过),因为重新启动的新 JRE 似乎在旧 JRE 中的某些文件上持有文件锁(或句柄?),因此它可以不要删除它们。 I also tried running a batch file that deletes the old JRE and replaces it with the new one, but again it is also unable to delete all the files in the old JRE.我还尝试运行一个批处理文件,删除旧的 JRE 并将其替换为新的,但同样也无法删除旧 JRE 中的所有文件。

Can this be done in Java, or do I have to write my update logic for each platform separately?这可以用 Java 完成,还是我必须分别为每个平台编写更新逻辑? What's the best way to do it?最好的方法是什么?

In theory in can be done but in practice there are hurdles.理论上可以做到,但在实践中存在障碍。

One of them is that on Windows, as long as some executable is executing the file on disk is write-protected.其中之一是在 Windows 上,只要某个可执行文件正在执行,磁盘上的文件就会被写保护。 On Unix this is not the case.在 Unix 上,情况并非如此。 And yet there may be strange effects if you manage to update half the application/JDK before something goes wrong.然而,如果您设法在出现问题之前更新一半的应用程序/JDK,可能会产生奇怪的效果。

I have not really checked but believe all applications that come with autoupdate features circumvent this problem by actually consisting of two applications.我没有真正检查过,但相信所有带有自动更新功能的应用程序实际上都包含两个应用程序来规避这个问题。 One of them is a thin wrapper that checks for updates and gets them installed, then starts the real application.其中之一是一个瘦包装器,它检查更新并安装它们,然后启动真正的应用程序。

If you want this for Java the thin wrapper already exists and is called WebStart.如果你想要这个用于 Java 的瘦包装器已经存在并且被称为 WebStart。 Since Java 9 Oracle no longer supports it, but then there is https://openwebstart.com/由于 Java 9 Oracle 不再支持它,但是有https://openwebstart.com/

暂无
暂无

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

相关问题 如何从Java应用程序读取图像文件? - How do i read an image file from my java application? 如何检查我的Java应用程序将在具有JRE 1.6 / 1.7的计算机上运行? - How do I check that my Java application will run on a machine with JRE 1.6/1.7? 如何控制与应用程序捆绑在一起的JRE版本? - How do I control what JRE version is bundled with my application? 如何从Web应用程序的根目录引用Java Web应用程序中的任何图像? - How do i refer to any image in my java web application from root of my web application? 如何在我的mac上将Java 7 JRE添加到Eclipse? - How do I add the Java 7 JRE to Eclipse on my mac? 如何使用特定的JRE交付我的Java应用程序? - How to deliver my Java application with a particular JRE? 如何将 JRE 捆绑到 Java 应用程序的 EXE 中? Launch4j 说“运行时丢失或损坏。” - How do I bundle a JRE into an EXE for a Java Application? Launch4j says “runtime is missing or corrupted.” 如何从与当前项目的JRE不同的JRE上的库jar中执行方法 - How do I execute a method from a library jar on a different JRE than my current project's JRE 我有一个Java应用程序在JRE 6中运行,但不在JRE 7中运行。如何在JRE7中运行该应用程序 - I have a Java App running in JRE 6 but not in JRE 7. How do i run the application in JRE7 如何确定Java应用程序的最低JRE版本和系统要求 - How to determine the minimum JRE version and system requirements for my Java application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM