在运行生产环境中添加类文件

发布于 2024-12-15 18:52:02 字数 140 浏览 7 评论 0原文

是否可以仅将 java 类的 .class 文件添加到正在运行的应用程序服务器上的 Ear 文件中,而不需要重新启动它。 JVM类加载器是如何这样加载的呢。我的印象是类加载器在启动时加载一个文件,如果您要更改正在运行的应用程序服务器中的类文件,则必须重新启动服务器。

Is it possible to just add .class files of java classes into the ear file on a running app server and not needing to restart it. How does the JVM classloader loads it in this way. I was under the impression that the classloader loads a file on startup and if you are going to change a class file in a running app server you will have to restart the server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

没有心的人 2024-12-22 18:52:02

EAR 是一个带有一些附加信息的 JAR 文件,因此您可以使用与 J2EE 容器相同的方法:创建一个新的类加载器(尝试 URLClassLoader)并为其提供加载新类所需的信息。

这适用于新课程;替换现有类是另一回事,因为这些类的所有实例都包含对原始类型的引用。没有通用的方法可以解决这个问题,但是 JRebel 的人编写了一个类加载器,它也可以做到这一点(有一些限制)。

An EAR is a JAR file with some additional information, so you can use the same approach as your J2EE container: Create a new classloader (try URLClassLoader) and give it the necessary information to load the new classes.

This works for new classes; replacing existing classes is a different matter because all instances of these classes contain references to the original type. There is no general approach to solve this but the guys at JRebel wrote a classloader which can do that too (with some limits).

娇纵 2024-12-22 18:52:02

如果该类尚未加载,您只需将其提供给类加载器即可使用,即将其编译到您从中进行部署的分解文件夹(例如 WEB-INF/classes)。当您从打包的 EAR 进行部署时,这不起作用,因为它们通常会在部署时分解。

当类已经加载时,您需要一个更改感知的类加载器。您的容器可以为您完成此操作,或者您可以查看 JRebel ,它效果很好。

If the class has not been loaded yet, you may simply make it available to the class loader, i.e. by compiling it to an exploded folder from which you deploy (WEB-INF/classes, for example). This does not work when you're deploying from a packaged-up EAR, as these are exploded at deployment time normally.

When the class has already been loaded, you need a change-aware classloader. Either your container does that for you, or you can take a look at JRebel which works great.

北风几吹夏 2024-12-22 18:52:02

对于热代码替换,您可以使用 JRebel
仅仅将 .class 添加到 Ear 中是不够的,因此您需要完全重建存档。

For hot code replacements, you can use JRebel
Merely adding .class into the ear would't suffice, so you need to do a full rebuild of the archive.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文