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.
Each application might use different versions of the same libraries, and must thus have a different classloader from the others in order to be able to have different versions of the same classes in a single JVM. but the web server has its own loader.it can have several classloaders.
You can create an instance of URLClassLoader to load new classes from a directory: URL dirUrl = new URL("file:/" + "path_to_dir" + "/"); // 1 URLClassLoader cl = new URLClassLoader(new URL[] {dirUrl}, getClass().
Dynamic loading is a technique for programmatically invoking the functions of a class loader at run time. Let us look at how to load classes dynamically by using Class. forName (String className); method, it is a static method. The above static method returns the class object associated with the class name.
They don't use any new classloaders; they extend the default ones.
https://www.jrebel.com/learn/how-does-jrebel-work
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.
they mention they don't use class loaders.
Every class uses a ClassLoader (except primitives). However, a library doesn't have to create additional ClassLoader.
Even a "Hello World" program will have two class loaders (one for boostrapping)
I thought the only way to load a class in Java was by using a class loader.
It is, but you can force the existing classloader to load your class which is hack but might be simpler to use.
(Correction) If you use null
as a ClassLoader, Unsafe.defineClass() will default to the ClassLoader of the caller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With