substratevm/docs/runtime-class-loading.md
Run-time class loading (a.k.a. "Crema") allows ClassLoader.defineClass to work at run time, creating new DynamicHubs.
It is enabled at build time with the -H:+RuntimeClassLoading option.
While this is sufficient to allow defineClass to work, additional setup may be needed depending on the specific use case.
URLClassLoader, use the build-time -H:EnableURLProtocols=jar option.-H:+AllowJRTFileSystem at build time, and ensure the java.home system property points to JDK at run time.
For example, pass -Djava.home=... when starting the native image.
Note that the only requirement for this directory is to contain a lib/modules file with the necessary classes.--initialize-at-run-time=jdk.internal.loader.ClassLoaders at build time, and set the java.class.path system property at run time.Run-time-loaded classes can link to other run-time-loaded classes or to build-time-loaded classes.
For build-time-loaded classes, the native image build process may have removed some methods or static fields.
Run-time class loading cannot reload a class that was already partially included into the native image at build time.
This will result in errors if run-time-loaded classes try to use such removed methods or static fields.
A typical way to address this is to use -H:Preserve=package=... at build time to ensure all methods and fields of a package are included in the native image.
getRecordComponents does not work.getPermittedSubClasses does not work.