Java 9, compatability issue with ClassLoader.getSystemClassLoader

You’ve run into the fact that the system class loader is no longer a URLClassLoader. As indicated by ClassLoader::getSystemClassLoader‘s return type, this was an implementation detail, albeit one that a non-negligible amount of code relied upon.

Judging by the comments, you are looking for a way to dynamically load classes at run time. As Alan Bateman points out, this can not be done in Java 9 by appending to the class path.

You should instead consider creating a new class loader for that. This has the added advantage that you’ll be able to get rid of the new classes as they are not loaded into the application class loader. If you’re compiling against Java 9, you should read up on layers – they give you a clean abstraction for loading an entirely new module graph.

Leave a Comment