4

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.

tshepang
  • 12,111
  • 21
  • 91
  • 136
sarmahdi
  • 1,098
  • 4
  • 21
  • 61

3 Answers3

1

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

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
1

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.

mgaert
  • 2,338
  • 21
  • 27
0

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.

Community
  • 1
  • 1
Sumit Bisht
  • 1,507
  • 1
  • 16
  • 31