2 years ago
#46756
facebook-100001358991487
Reload existing class file dynamically for Java Application
Scenario
I am working on a big application consist of hundred of class files. As part of giving a patch to fix the issue in production set up, we generally give a jar file. This jar file contains the class file(s) which includes a fix and put inside one patch path(This is the path which is used to put the patches/fixes as jar file). In the production set up, we recommend to restart the application. As part of restart , application first looks the class files from patch path and then from the other path where all the class files are present. So this way first classes from patch path is loaded.
Expectation
Now instead of restarting the application, i want to reload the class file so that restart of application can be avoided. I checked in net and found the following:
- We can use customize/dynamic class loader as well. I think this is also not full proof way of doing it.
- URLClassLoader is also one of the option.
- If we use customize class loader, then we have to load all the application class files using this because class file can refer to another class file if it is loaded from the same class loader. This is what i read from net. If yes, then i think this option is not valid. right ?
After checking all the above options, i still feel the above options are not good enough to load the existing class file (which is getting used in running application as well) at run time.
So question arises that is there any full proof possibily to replace the class file at run time for java application. if Yes, Could you please guide in this regard. Also, if this kind of requirement or question is already answered properly(I didn't find any good link), please redirect
NOTE: I think OSGi is also one option. But i feel not possible in such a big application since it will requires lot of changes which i want to avoid.
Please suggest.
java
classloader
urlclassloader
0 Answers
Your Answer