Search code examples
javaclassdeploymentappserver

Adding class files in running production environment


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.


Solution

  • 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).