Class.forName works with Java 8, but goes wrong with Java 11

In an application I have:
Class.forName(“org.h2.Driver”)

When using Java8 this works without a problem, but when using Java11 I get:

java.lang.ClassNotFoundException: java.sql.Driver
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:550)
at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:458)
at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:452)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:451)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)

What could be the problem?

My guess would be that the classes of the java.sql module aren’t on the classpath for some reason.

I use the word module here like I know what it means, but don’t let it fool you: I don’t have a clue.

1 Like

How would I reproduce the problem on my own computer? Whatever has gone wrong here, it must have to do with the tools you are using and how you have configured them.

org.h2.Driver isn’t in the default classpath of a stock JDK 8 installation, so you’ll probably need to start by figuring out (and, if necessary, telling us) how or why this does work for you on 8.