Hello Team,
I need to migrate our legacy application from java8 to java17. While running the application, I encountered the following exception with OpenJDK 17. This worked fine with Java 8, but the new class loader mechanism under the module system is causing issues. What should be the solution for this?
java -version
openjdk version "17.0.11" 2024-04-16
OpenJDK Runtime Environment Temurin-17.0.11+9 (build 17.0.11+9)
OpenJDK 64-Bit Server VM Temurin-17.0.11+9 (build 17.0.11+9, mixed mode, sharing)
Exception in thread "main" java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')
at sentinel.command.SentinelBoot.addToClassPath(SentinelBoot.java:194)
at sentinel.command.SentinelBoot.initClassPath(SentinelBoot.java:63)
at sentinel.command.SentinelStarter.initStarter(SentinelStarter.java:54)
at sentinel.command.TrkServer.main(TrkServer.java:48)
Sharing few code snippets for reference:
URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader();
Class<URLClassLoader> sysclass = URLClassLoader.class;
Method method = sysclass.getDeclaredMethod("addURL", parameters);
method.setAccessible(true);
method.invoke(sysloader, new Object[]{u});
I am stuck for so many days, nowhere getting any solutions. Please guide me. Thanks in advance!