jar:
scheme URL (see java.net.JarURLConnection ) is assumed to refer to a
JAR file. Any file: scheme URL that ends with a '/' is assumed to
refer to a directory. Otherwise, the URL is assumed to refer to a JAR file
which will be opened as needed.
This class loader supports the loading of classes and resources from the contents of a multi-release JAR file that is referred to by a given URL.
| Modifier and Type | Field and Description |
|---|---|
| private final WeakHashMap | |
| private final URLClassPath |
| Access | Constructor and Description |
|---|---|
| public | URLClassLoader(URL[]
the URLs from which to load classes and resources urls, ClassLoader the parent class loader for delegation, can be parent)null
for the bootstrap class loaderConstructs a new URLClassLoader for the given URLs. |
| public | URLClassLoader(URL[]
the URLs from which to load classes and resources urls)Constructs a new URLClassLoader for the specified URLs using the system class loader as the parent. |
| public | URLClassLoader(URL[]
the URLs from which to load classes and resources urls, ClassLoader the parent class loader for delegation, can be parent, URLStreamHandlerFactory null
for the bootstrap class loaderthe URLStreamHandlerFactory to use when creating URLs factory)Constructs a new URLClassLoader for the specified URLs, parent class loader, and URLStreamHandlerFactory. |
| public | URLClassLoader(String
class loader name; or name, URL[] null if not namedthe URLs from which to load classes and resources urls, ClassLoader the parent class loader for delegation, can be parent)null
for the bootstrap class loaderConstructs a new named |
| public | URLClassLoader(String
class loader name; or name, URL[] null if not namedthe URLs from which to load classes and resources urls, ClassLoader the parent class loader for delegation, can be parent, URLStreamHandlerFactory null
for the bootstrap class loaderthe URLStreamHandlerFactory to use when creating URLs factory)Constructs a new named |
| Modifier and Type | Method and Description |
|---|---|
| protected void | |
| public void | close()
Implements java. Closes this URLClassLoader, so that it can no longer be used to load new classes or resources that are defined by this loader. |
| private Class | |
| protected Package | Returns: the newly definedPackage objectthe package name name, Manifest the man, URL Manifest containing package version and sealing
informationthe code source url for the package, or null if none url)Defines a new package by name in this |
| protected Class | Returns: the resulting classthe name of the class name)Overrides java. Finds and loads the class with the specified name from the URL search path. |
| public URL | Returns: aURL for the resource, or null
if the resource could not be found, or if the loader is closed.the name of the resource name)Overrides java. Finds the resource with the specified name on the URL search path. |
| public Enumeration | Returns: AnEnumeration of URLs.
If the loader is closed, the Enumeration contains no elements.the resource name name)Overrides java. Returns an Enumeration of URLs representing all of the resources on the URL search path having the specified name. |
| private Package | |
| protected PermissionCollection | Returns: an empty Permission collectionthe codesource)CodeSourceOverrides java. Returns an empty Permission collection. |
| public InputStream | Returns: An input stream for reading the resource, ornull
if the resource could not be foundThe resource name name)Overrides java. Returns an input stream for reading the specified resource. |
| public URL[] | Returns: the search path of URLs for loading classes and resources.Returns the search path of URLs for loading classes and resources. |
| private boolean | |
| public static URLClassLoader | Returns: the resulting class loaderthe URLs to search for classes and resources urls, final ClassLoader the parent class loader for delegation parent)Creates a new instance of URLClassLoader for the specified URLs and parent class loader. |
| public static URLClassLoader | Returns: the resulting class loaderthe URLs to search for classes and resources urls)Creates a new instance of URLClassLoader for the specified URLs and default parent class loader. |
| closeables | back to summary |
|---|---|
| private final WeakHashMap<Closeable, Void> closeables | |
| ucp | back to summary |
|---|---|
| private final URLClassPath ucp | |
| URLClassLoader | back to summary |
|---|---|
| public URLClassLoader(URL[] urls, ClassLoader parent) Constructs a new URLClassLoader for the given URLs. The URLs will be
searched in the order specified for classes and resources after first
searching in the specified parent class loader. Any API Note If
| |
| URLClassLoader | back to summary |
|---|---|
| public URLClassLoader(URL[] urls) Constructs a new URLClassLoader for the specified URLs using the system class loader as the parent. The URLs will be searched in the order specified for classes and resources after first searching in the parent class loader. Any URL that ends with a '/' is assumed to refer to a directory. Otherwise, the URL is assumed to refer to a JAR file which will be downloaded and opened as needed.
| |
| URLClassLoader | back to summary |
|---|---|
| public URLClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) Constructs a new URLClassLoader for the specified URLs, parent class loader, and URLStreamHandlerFactory. The parent argument will be used as the parent class loader for delegation. The factory argument will be used as the stream handler factory to obtain protocol handlers when creating new jar URLs. API Note If
| |
| URLClassLoader | back to summary |
|---|---|
| public URLClassLoader(String name, URL[] urls, ClassLoader parent) Constructs a new named API Note If
| |
| URLClassLoader | back to summary |
|---|---|
| public URLClassLoader(String name, URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) Constructs a new named API Note If
| |
| addURL | back to summary |
|---|---|
| protected void addURL(URL url) Appends the specified URL to the list of URLs to search for classes and resources.
If the URL specified is
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Implements java. Closes this URLClassLoader, so that it can no longer be used to load new classes or resources that are defined by this loader. Classes and resources defined by any of this loader's parents in the delegation hierarchy are still accessible. Also, any classes or resources that are already loaded, are still accessible.
In the case of jar: and file: URLs, it also closes any files
that were opened by it. If another thread is loading a
class when the
The method makes a best effort attempt to close all opened files,
by catching
| |
| defineClass | back to summary |
|---|---|
| private Class | |
| definePackage | back to summary |
|---|---|
| protected Package definePackage(String name, Manifest man, URL url) Defines a new package by name in this
| |
| findClass | back to summary |
|---|---|
| protected Class Overrides java. Finds and loads the class with the specified name from the URL search path. Any URLs referring to JAR files are loaded and opened as needed until the class is found.
| |
| findResource | back to summary |
|---|---|
| public URL findResource(final String name) Overrides java. Finds the resource with the specified name on the URL search path. | |
| findResources | back to summary |
|---|---|
| public Enumeration Overrides java. Returns an Enumeration of URLs representing all of the resources on the URL search path having the specified name.
| |
| getAndVerifyPackage | back to summary |
|---|---|
| private Package getAndVerifyPackage(String pkgname, Manifest man, URL url) | |
| getPermissions | back to summary |
|---|---|
| protected PermissionCollection getPermissions(CodeSource codesource) Overrides java. Returns an empty Permission collection.
| |
| getResourceAsStream | back to summary |
|---|---|
| public InputStream getResourceAsStream(String name) Overrides java. Returns an input stream for reading the specified resource. If this loader is closed, then any resources opened by this method will be closed. The search order is described in the documentation for
| |
| getURLs | back to summary |
|---|---|
| public URL[] getURLs() Returns the search path of URLs for loading classes and resources. This includes the original list of URLs specified to the constructor, along with any URLs subsequently appended by the addURL() method.
| |
| isSealed | back to summary |
|---|---|
| private boolean isSealed(String name, Manifest man) | |
| newInstance | back to summary |
|---|---|
| public static URLClassLoader newInstance(final URL[] urls, final ClassLoader parent) Creates a new instance of URLClassLoader for the specified URLs and parent class loader.
| |
| newInstance | back to summary |
|---|---|
| public static URLClassLoader newInstance(final URL[] urls) Creates a new instance of URLClassLoader for the specified URLs and default parent class loader.
| |