saker.util Documentation TaskDoc JavaDoc Packages
public class ClassLoaderUtil
Utility class containing functions related to class loaders.
Methods
public static ClassLoader
Gets a ClassLoader that can be used to access resources defined by the bootstrap class loader.
public static InputStream
Opens an input stream for the resource with the given name in the bootstrap classloader.
public static URL
Finds a resource URL in the bootstrap classloader.
public static Enumeration<URL>
Finds resources in the bootstrap classloader.
public static ClassLoader
Returns the classloader which should be used as a parent to new classloaders in order to access the JRE classes.
Gets a ClassLoader that can be used to access resources defined by the bootstrap class loader.

As the bootstrap class loader is represented by the null parent class loader, it is not possible to directly access resources of it. You need to create a new instance of ClassLoader with null parent to access resources from it.

This method returns a such class loader, which has null as its parent, and doesn't load any classes. In general there is no use for using the class loader returned by this method, however it can be useful when subclassing ClassLoader and implementing complex functionality.

See the documentation of ClassLoader for more info about the bootstrap class loader.

A classloader that has null parent and loads no classes.
Opens an input stream for the resource with the given name in the bootstrap classloader.

This method calls ClassLoader.getResourceAsStream(String) on the bootstrap classloader, which is retrieved using getBootstrapLoader().

nameThe resource name.
The opened input stream or null if not found.
Finds a resource URL in the bootstrap classloader.

This method calls ClassLoader.getResource(String) on the bootstrap classloader, which is retrieved using getBootstrapLoader().

nameThe resource name.
The found resource URL or null.
Finds resources in the bootstrap classloader.

This method calls ClassLoader.getResources(String) on the bootstrap classloader, which is retrieved using getBootstrapLoader().

nameThe resource name.
An enumeration of the found resources.
IOExceptionIn case of I/O error.
Returns the classloader which should be used as a parent to new classloaders in order to access the JRE classes.

This is important to use, when compatibility with JDK 8 and the JDK 9+ should be achieved.

For example, when one wants to load Processor, it is necessary on JDK 9+ to have the platform classloader as a parent, as the default null parent doesn't contain the requested class. On JDK 8, this will return null, as the classloaders delegate the loading to the bootstrap classloader, which contains all the JRE classes. On JDK 9+, this will return ClassLoader.getPlatformClassLoader()

The parent classloader to use.