Frage

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.

War es hilfreich?

Lösung

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

Andere Tipps

If the class has not been loaded yet, you may simply make it available to the class loader, i.e. by compiling it to an exploded folder from which you deploy (WEB-INF/classes, for example). This does not work when you're deploying from a packaged-up EAR, as these are exploded at deployment time normally.

When the class has already been loaded, you need a change-aware classloader. Either your container does that for you, or you can take a look at JRebel which works great.

For hot code replacements, you can use JRebel Merely adding .class into the ear would't suffice, so you need to do a full rebuild of the archive.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top