Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to make my default classloader a URLClassloader in Java 11?

4ec39370-0a2c-4350-9d5a-9d7438667d94Aug 10 2020 — edited Aug 11 2020

I am trying to migrate from Java 8 to Java 11 and the most painful surprise was that the AppClassLoader (also known as the application or system classloader) can no longer be cast as a URLClassloader.

Worse, everything I found through google that refers to using a custom classloader are simple examples that show how to create a new classloader (yes, even extending URLClassloader) but stop there, with a manual instantiation of a class.  Nothing on how to make it so that all classes loaded *after* instantiating it to be loaded through *that* classloader instead of the previous default.

So I have a couple of questions:

1) Does the Tomcat 9 running on Java 11 *common* classloader (the one used by libraries) still return a URLClassloader?  I am guessing yes, since they built this whole container classloader hierarchy, so I am hoping they used the URLClassloader as their base.  But if no, can someone recommend a different web application server that relies on URLClassLoaders?

2) For command line applications this is even more critical.  I need to create a URLClassloader (with the App class loader as its parent) and then make it the default for the rest of the application classloading.  Can someone point me to a good guide for this kind of design?

Comments

Processing

Post Details

Added on Aug 10 2020
0 comments
531 views