Question

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

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

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

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

Changes will be happening only in two.jar

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.

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top