假设 jar 在 JVM 中运行,是否可以卸载当前运行的 Jar 并将其从系统中删除.下载新版本并将其重命名为与上一个 Jar 相同的名称,然后初始化新 Jar,从而在 JVM 中创建 Jar 的无缝更新.甚至可以指示 JVM 执行此操作吗?是否可以在运行时更新 Jar?
Given a jar runs within a JVM would it be possible to unload the current running Jar and remove it from the system. Download a new version and rename it with the same name of the last Jar and then initialise the new Jar, creating a seamless update of the Jar within the JVM. Is it even possible to instruct the JVM to perform this action? Is it even possible to update a Jar whilst its running?
这是我以前见过很多次的事情(我自己也做过).我写了一些可能出现的问题/解决方案.
This is something that I've seen done many times before (and also done myself). I composed some points of the problems/solutions that might arise.
总而言之,当您想要实现 JAR 重新加载时,您可能会遇到很多问题.幸运的是,有一些方法可以将风险降到最低.最安全的方法是做类似的事情以获得相同的效果.最干净的是自定义类加载器和 JAR 文件版本控制.
All in all there are many issues that you might run into when you want to achieve JAR reloading. Luckily there are ways how to minimise the risks. The safest way is to do something similar to get the same effect. Cleanest is custom classloaders and JAR file versioning.
这篇关于在运行时更新 JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!