热交换java中的jar文件 [英] Hot swapping the jar files in java

查看:117
本文介绍了热交换java中的jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个jar文件。
One.jar包含启动进程的主要方法,其他two.jar只包含类文件。

I have two jar files. One.jar contains main method to start the process and other two.jar contains just class files.

在One.jar中我引用了两个.jar它的清单类路径。

In One.jar I have referenced two.jar in its manifest classpath.

One.jar包含使用Class.forName()动态加载类的机制

One.jar contains mechanism to dynamically load the classes using Class.forName()

我想要终身只部署One.jar一次。不会对其进行任何更改。

I want to deploy the One.jar only once for lifetime. Will not be making any changes to it.

更改将仅在two.jar中发生

Changes will be happening only in two.jar

我想要用更新的two.jar热交换two.jar。我已经看过其他关于热交换的帖子,就像OSGi一样,为ANT热插拔,但没有任何帮助我。

I want to hot swap the two.jar with updated two.jar. I have seen other posts about hot swapping too like OSGi, hotswap for ANT but nothing helps me.

经过一番研究后发现JRebel确实做得更好但是我真的不知道如何将它与这些罐子结合起来?我坚持了将近2天。只需要几步信息即可完成。有人帮帮我...这对我来说真的非常重要...谢谢

After a little research found out that JRebel does this really better but I really dont know how to integrate it with these jars? I am stuck on this for almost 2 days. Just need few steps of info to get this done. Someone help me please... This is really very important to me... Thanks

推荐答案

嘿,我终于得到了一个解决方案。我真的不知道我会想出这么简单的解决方案。我接受了@ThorbjørnRavnAndersen的想法。我所做的只是首先获取jar文件的时间戳,然后使用URLClassLoader加载jar。如果jar文件的时间戳发生了变化(即当我用更新的jar替换jar时),那么我将使用close()丢弃旧的URLClassLoader对象,并再次使用URLClassLoader加载新的jar。我每次都要检查的唯一事情是jar的时间戳是否改变。希望这个答案能帮助其他人。谢谢大家的支持。

Hey all I have finally got a solution for this. I really don't know that I will come up with such a easy solution. I took the idea of @Thorbjørn Ravn Andersen. All I did was first get the timestamp of the jar file and then load the jar using URLClassLoader. If the timestamp of the jar file changes (i.e. when I replace the jar with updated jar) then I am discarding old URLClassLoader object using close() and loading the new jar with URLClassLoader again. The only thing I have to check every time is whether the timestamp of jar changes or not. Hope this answer helps other people too. Thank you all for your support.

这篇关于热交换java中的jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆