GraalVM developer here. As mentioned in the limitations document, dynamically loading classes cannot be supported on SubstrateVM. However, that doesn’t mean that we cannot have ClassLoader
objects in the image, especially since the ClassLoader
is also used to load resources. This is being currently worked on and classOf[MyClass].getClassLoader
and Thread.currentThread.getContextClassLoader
should work in the near future. Of course for classOf[MyClass].getClassLoader
to work the class needs to be visible during native image building and properly registered for reflection. We are also working on automatically detecting patterns like Class.forName("x.y.z.MyClass")
and register referenced classes for reflection as long as the class name is a constant or it can be constant folded.
8 Likes