This is due to the Java 9 architecture precluding use of URLClassLoader as a superclass for the system ClassLoaders.
I implemented the following changes with noted caveats:
Add the ClassPath property to the jar Manifest file to provide startup classpath additions.
When an extended classpath is required, I use:
Class.forName("nameofclass", true, new URLClassLoader(urlarrayofextrajarsordirs));
The above line also attaches the extended classpath to nameofclass so any other class definitions in nameofclass will also resolve.
java.util.ServiceLoader uses the thread's ClassLoader context Thread.currentThread().setContextClassLoader(specialloader);
java.sql.DriverManager does honors the calling class' ClassLoader, -not- the Thread's ClassLoader. Create Driver directly using Class.forName("drivername", true, new URLClassLoader(urlarrayofextrajarsordirs).newInstance();
javax.activation uses the thread's ClassLoader context (important for javax.mail).
Hopefully this will help the thousands of other authors who have relied on the application ClassLoader being a subclass of URLClassLoader.
Further elaboration on java.sql.DriverManager issue. While Class.forName(..., true, classloader) properly loads the class for the JDBC driver and registers it with DriverManager, it is unusable via DriverManager because DriverManager tries Class.forName(jdbcdrivername, true, caller.getClassLoader()) which fails since class caching is done at the child ClassLoader level, not the parent level.
"Hopefully this will help the thousands of other authors ..."
NO, it most certainly does not help at all.
This "answer" does *NOT* answer the questions or address the issues.
The OP asked how to fix some code, the "answer" contains vague suggestions and gobbledygook.
Answer the OP's questions. What does the OP have to do to fix their code ?
I have searched extensively on this issue, found dozens of threads, and NONE answer the issues or contain any fixes that work. Examples:
* Java example with ClassLoader
* Java 9, compatability issue with ClassLoader.getSystemClassLoader
* Java JDBC connection error with JDK 9
* How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException in Java 9
* Add jar to classpath at runtime under java 9
* Base ClassLoader No Longer from URLClassLoader - SHODOV
* Java 9 Migration Guide: The Seven Most Common Challenges - nipa 24.07.2017
So, can anyone actually fix the OP's code ? Or do the 1,000's of us having problems with Java 9 just go back to using Java 8 - a product that actually worked and didn't stuff things up for no reason.
Hopefully this will help the thousands of other authors