// It seems there is nothing we can do if the current class loader is not a ClassRealm.
return;
}
// Modify the current class loader so that classes that was not loaded during the Maven build will be loaded by the new class loader.
final ClassRealm classRealm = (ClassRealm) classLoader;
ClassLoader newClassLoader = new URLClassLoader(classRealm.getURLs(), classRealm.getParentClassLoader()) {
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
// We should first check whether the requested class was already loaded by the old class loader in order not to break compatibility with already loaded classes.
Class<?> clazz = classRealm.loadClassFromSelf(name);
return clazz != null ? clazz : super.loadClass(name, resolve);
}
};
classRealm.setParentClassLoader(newClassLoader);
}