public final class JarFileLoader extends URLClassLoader
URLClassLoader, providing
the ability to load a class from a Java jar file introduced
after JVM starts. This capability is needed by long
running Java applications which cannot be restarted but need
to access a new jar file dropped into a well-known location.
That jar file path may be added to the JarFileLoader
via addJar(java.lang.String) and then
packages() used to determine the newly
available packages.| Modifier and Type | Field and Description |
|---|---|
static String |
URL_FORMAT
Place the JAR file path within this string to create the
JAR URL.
|
| Constructor and Description |
|---|
JarFileLoader(URL[] urls)
Constructs a new JAR class loader for the specified URLs
and the default
ClassLoader. |
JarFileLoader(URL[] urls,
ClassLoader parent)
Constructs a new JAR class loader for the specified URLs
and parent class loader.
|
JarFileLoader(URL[] urls,
ClassLoader parent,
URLStreamHandlerFactory factory)
Constructs a new JAR class loader for the specified URLs,
parent class loader, and URL stream handler factory.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addJar(String path)
Appends the JAR file path to the URL search list.
|
Package[] |
packages()
Returns all the
Packages defined by this
class loader and its ancestors. |
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstancedefineClass, defineClassclearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSignerspublic static final String URL_FORMAT
public JarFileLoader(URL[] urls)
ClassLoader. The URLs are searched from index
zero to urls.length - 1 for classes and resources
after first delegating the search to
parent. Any URL ending in "/" is assumed to refer
to a directory. Otherwise, the URL is assumed to be a JAR
file which will be downloaded and opened as necessary.urls - the class and resource load path.SecurityException - if a security manager exists and its
checkCreateClassLoader method does not allow
creation of a class loader.public JarFileLoader(URL[] urls, ClassLoader parent)
urls.length - 1 for classes and resources
after first delegating the search to
parent. Any URL ending in "/" is assumed to refer
to a directory. Otherwise, the URL is assumed to be a JAR
file which will be downloaded and opened as necessary.urls - the class and resource load path.parent - the delegate parent class loader.SecurityException - if a security manager exists and its
checkCreateClassLoader method does not allow
creation of a class loader.public JarFileLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory)
parent argument is the delegate class loader. The
factory argument is used to obtain protocol
handlers when creating new JAR URLs. The search order is:
parent delegate first.
urls from index zero to
urls.length - 1.
urls - the class and resource load path.parent - the delegate parent class loader.factory - the protocol handler factory.SecurityException - if a security manager exists and its
checkCreateClassLoader method does not allow
creation of a class loader.public Package[] packages()
Packages defined by this
class loader and its ancestors.public void addJar(String path) throws IOException
path - path to a readable JAR file.FileNotFoundException - if path refers to a non-existent file.IOException - if path either does not refer to a regular file or
the file cannot be read.MalformedURLException - if path could not be parsed by
URL.Copyright © 2021. All rights reserved.