Class ApplicationClassLoader

All Implemented Interfaces:
Closeable, AutoCloseable

public final class ApplicationClassLoader extends URLClassLoader
An URLClassLoader whose classpath can be modified at runtime.

This is intended for use by applications that want to load classes using the usual system or context class loader, but need the ability to add URLs to the classpath that is searched. In JDK 9 and later, the system class loader can no longer be directly modified (this previously used an ugly reflection hack anyway). This class effectively restores that capability, by overriding addURL() and making it public.

This class also provides a way to lookup existing instances by parent; see getInstance(). These instances are cached using weak references to avoid a memory leak.

Instances work together to behave like a singleton; an URL added to any instance by addURL() is automagically added to all existing and future instances.