javaclassloaderjrebel

How to dynamically load a Java class without using a class loader?


I recently saw an online presentation of JRebel in which they explain what their product does, in one of the slides they mention they don't use class loaders (see screenshot below).

I have some projects in which I use class loaders for dynamically loading classes at runtime, for example for dependency injection (like in the Maker Factory framework that I developed). I thought the only way to load a class in Java was by using a class loader.

enter image description here


Solution

  • Disclaimer: I'm involved with JRebel development

    Technically, it is possible to bypass the classloader with some Unsafe magic, and JVM leverages that with lambdas when creating the runtime anonymous classes (in Java 8).

    However, JRebel actually integrates with the existing classloaders and doesn't create new ones - that's what the slide mean. JRebel doesn't drop the existing classloader when it has to reload a class. Instead, it loads and versions the classes within the existing classloaders.