Hot swapping the jar files in java

点点圈 提交于 2019-11-30 21:33:31

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.

As I am directly related to JRebel (I'm the product manager), I probably can give some pointers for configuration.

To update the classes within a JAR with JRebel, place a dedicated rebel.xml configuration file into that two.jar which will point to the directory where the compiled classes of two.jar are.

     one.jar ---> two.jar
                   `- rebel.xml   // points to two/project/classes

Here's the doc with the examples: http://manuals.zeroturnaround.com/jrebel/standalone/config.html#configuring-jars

Depending on how your project is set up, the IDE plugins would help automating this.

Please note that if your intention is to do this procedure in live system, then JRebel is not a tool for this kind of purpose.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!