java.net
Class URLClassLoader

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.lang.ClassLoader sample code for java.lang.ClassLoader definition code for java.lang.ClassLoader 
      extended by java.security.SecureClassLoader sample code for java.security.SecureClassLoader definition code for java.security.SecureClassLoader 
          extended by java.net.URLClassLoader
Direct Known Subclasses:
MLet sample code for javax.management.loading.MLet definition code for javax.management.loading.MLet

public class URLClassLoader
extends SecureClassLoader sample code for java.security.SecureClassLoader definition code for java.security.SecureClassLoader

This class loader is used to load classes and resources from a search path of URLs referring to both JAR files and directories. 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 opened as needed.

The AccessControlContext of the thread that created the instance of URLClassLoader will be used when subsequently loading classes and resources.

The classes that are loaded are by default granted permission only to access the URLs specified when the URLClassLoader was created.

Since:
1.2

Constructor Summary
URLClassLoader sample code for java.net.URLClassLoader.URLClassLoader(java.net.URL[]) definition code for java.net.URLClassLoader.URLClassLoader(java.net.URL[]) (URL sample code for java.net.URL definition code for java.net.URL [] urls)
          Constructs a new URLClassLoader for the specified URLs using the default delegation parent ClassLoader.
URLClassLoader sample code for java.net.URLClassLoader.URLClassLoader(java.net.URL[], java.lang.ClassLoader) definition code for java.net.URLClassLoader.URLClassLoader(java.net.URL[], java.lang.ClassLoader) (URL sample code for java.net.URL definition code for java.net.URL [] urls, ClassLoader sample code for java.lang.ClassLoader definition code for java.lang.ClassLoader  parent)
          Constructs a new URLClassLoader for the given URLs.
URLClassLoader sample code for java.net.URLClassLoader.URLClassLoader(java.net.URL[], java.lang.ClassLoader, java.net.URLStreamHandlerFactory) definition code for java.net.URLClassLoader.URLClassLoader(java.net.URL[], java.lang.ClassLoader, java.net.URLStreamHandlerFactory) (URL sample code for java.net.URL definition code for java.net.URL [] urls, ClassLoader sample code for java.lang.ClassLoader definition code for java.lang.ClassLoader  parent, URLStreamHandlerFactory sample code for java.net.URLStreamHandlerFactory definition code for java.net.URLStreamHandlerFactory  factory)
          Constructs a new URLClassLoader for the specified URLs, parent class loader, and URLStreamHandlerFactory.
 
Method Summary
protected  void addURL sample code for java.net.URLClassLoader.addURL(java.net.URL) definition code for java.net.URLClassLoader.addURL(java.net.URL) (URL sample code for java.net.URL definition code for java.net.URL  url)
          Appends the specified URL to the list of URLs to search for classes and resources.
protected  Package sample code for java.lang.Package definition code for java.lang.Package definePackage sample code for java.net.URLClassLoader.definePackage(java.lang.String, java.util.jar.Manifest, java.net.URL) definition code for java.net.URLClassLoader.definePackage(java.lang.String, java.util.jar.Manifest, java.net.URL) (String sample code for java.lang.String definition code for java.lang.String  name, Manifest sample code for java.util.jar.Manifest definition code for java.util.jar.Manifest  man, URL sample code for java.net.URL definition code for java.net.URL  url)
          Defines a new package by name in this ClassLoader.
protected  Class sample code for java.lang.Class definition code for java.lang.Class <?> findClass sample code for java.net.URLClassLoader.findClass(java.lang.String) definition code for java.net.URLClassLoader.findClass(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  name)
          Finds and loads the class with the specified name from the URL search path.
 URL sample code for java.net.URL definition code for java.net.URL findResource sample code for java.net.URLClassLoader.findResource(java.lang.String) definition code for java.net.URLClassLoader.findResource(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  name)
          Finds the resource with the specified name on the URL search path.
 Enumeration sample code for java.util.Enumeration definition code for java.util.Enumeration <URL sample code for java.net.URL definition code for java.net.URL > findResources sample code for java.net.URLClassLoader.findResources(java.lang.String) definition code for java.net.URLClassLoader.findResources(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  name)
          Returns an Enumeration of URLs representing all of the resources on the URL search path having the specified name.
protected  PermissionCollection sample code for java.security.PermissionCollection definition code for java.security.PermissionCollection getPermissions sample code for java.net.URLClassLoader.getPermissions(java.security.CodeSource) definition code for java.net.URLClassLoader.getPermissions(java.security.CodeSource) (CodeSource sample code for java.security.CodeSource definition code for java.security.CodeSource  codesource)
          Returns the permissions for the given codesource object.
 URL sample code for java.net.URL definition code for java.net.URL [] getURLs sample code for java.net.URLClassLoader.getURLs() definition code for java.net.URLClassLoader.getURLs() ()
          Returns the search path of URLs for loading classes and resources.
static URLClassLoader sample code for java.net.URLClassLoader definition code for java.net.URLClassLoader newInstance sample code for java.net.URLClassLoader.newInstance(java.net.URL[]) definition code for java.net.URLClassLoader.newInstance(java.net.URL[]) (URL sample code for java.net.URL definition code for java.net.URL [] urls)
          Creates a new instance of URLClassLoader for the specified URLs and default parent class loader.
static URLClassLoader sample code for java.net.URLClassLoader definition code for java.net.URLClassLoader newInstance sample code for java.net.URLClassLoader.newInstance(java.net.URL[], java.lang.ClassLoader) definition code for java.net.URLClassLoader.newInstance(java.net.URL[], java.lang.ClassLoader) (URL sample code for java.net.URL definition code for java.net.URL [] urls, ClassLoader sample code for java.lang.ClassLoader definition code for java.lang.ClassLoader  parent)
          Creates a new instance of URLClassLoader for the specified URLs and parent class loader.
 
Methods inherited from class java.security.SecureClassLoader sample code for java.security.SecureClassLoader definition code for java.security.SecureClassLoader
defineClass sample code for java.security.SecureClassLoader.defineClass(java.lang.String, byte[], int, int, java.security.CodeSource) definition code for java.security.SecureClassLoader.defineClass(java.lang.String, byte[], int, int, java.security.CodeSource) , defineClass sample code for java.security.SecureClassLoader.defineClass(java.lang.String, java.nio.ByteBuffer, java.security.CodeSource) definition code for java.security.SecureClassLoader.defineClass(java.lang.String, java.nio.ByteBuffer, java.security.CodeSource)
 
Methods inherited from class java.lang.ClassLoader sample code for java.lang.ClassLoader definition code for java.lang.ClassLoader
clearAssertionStatus sample code for java.lang.ClassLoader.clearAssertionStatus() definition code for java.lang.ClassLoader.clearAssertionStatus() , defineClass sample code for java.lang.ClassLoader.defineClass(byte[], int, int) definition code for java.lang.ClassLoader.defineClass(byte[], int, int) , defineClass sample code for java.lang.ClassLoader.defineClass(java.lang.String, byte[], int, int) definition code for java.lang.ClassLoader.defineClass(java.lang.String, byte[], int, int) , defineClass sample code for java.lang.ClassLoader.defineClass(java.lang.String, byte[], int, int, java.security.ProtectionDomain) definition code for java.lang.ClassLoader.defineClass(java.lang.String, byte[], int, int, java.security.ProtectionDomain) , defineClass sample code for java.lang.ClassLoader.defineClass(java.lang.String, java.nio.ByteBuffer, java.security.ProtectionDomain) definition code for java.lang.ClassLoader.defineClass(java.lang.String, java.nio.ByteBuffer, java.security.ProtectionDomain) , definePackage sample code for java.lang.ClassLoader.definePackage(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.net.URL) definition code for java.lang.ClassLoader.definePackage(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.net.URL) , findLibrary sample code for java.lang.ClassLoader.findLibrary(java.lang.String) definition code for java.lang.ClassLoader.findLibrary(java.lang.String) , findLoadedClass sample code for java.lang.ClassLoader.findLoadedClass(java.lang.String) definition code for java.lang.ClassLoader.findLoadedClass(java.lang.String) , findSystemClass sample code for java.lang.ClassLoader.findSystemClass(java.lang.String) definition code for java.lang.ClassLoader.findSystemClass(java.lang.String) , getPackage sample code for java.lang.ClassLoader.getPackage(java.lang.String) definition code for java.lang.ClassLoader.getPackage(java.lang.String) , getPackages sample code for java.lang.ClassLoader.getPackages() definition code for java.lang.ClassLoader.getPackages() , getParent sample code for java.lang.ClassLoader.getParent() definition code for java.lang.ClassLoader.getParent() , getResource sample code for java.lang.ClassLoader.getResource(java.lang.String) definition code for java.lang.ClassLoader.getResource(java.lang.String) , getResourceAsStream sample code for java.lang.ClassLoader.getResourceAsStream(java.lang.String) definition code for java.lang.ClassLoader.getResourceAsStream(java.lang.String) , getResources sample code for java.lang.ClassLoader.getResources(java.lang.String) definition code for java.lang.ClassLoader.getResources(java.lang.String) , getSystemClassLoader sample code for java.lang.ClassLoader.getSystemClassLoader() definition code for java.lang.ClassLoader.getSystemClassLoader() , getSystemResource sample code for java.lang.ClassLoader.getSystemResource(java.lang.String) definition code for java.lang.ClassLoader.getSystemResource(java.lang.String) , getSystemResourceAsStream sample code for java.lang.ClassLoader.getSystemResourceAsStream(java.lang.String) definition code for java.lang.ClassLoader.getSystemResourceAsStream(java.lang.String) , getSystemResources sample code for java.lang.ClassLoader.getSystemResources(java.lang.String) definition code for java.lang.ClassLoader.getSystemResources(java.lang.String) , loadClass sample code for java.lang.ClassLoader.loadClass(java.lang.String) definition code for java.lang.ClassLoader.loadClass(java.lang.String) , loadClass sample code for java.lang.ClassLoader.loadClass(java.lang.String, boolean) definition code for java.lang.ClassLoader.loadClass(java.lang.String, boolean) , resolveClass sample code for java.lang.ClassLoader.resolveClass(java.lang.Class) definition code for java.lang.ClassLoader.resolveClass(java.lang.Class) , setClassAssertionStatus sample code for java.lang.ClassLoader.setClassAssertionStatus(java.lang.String, boolean) definition code for java.lang.ClassLoader.setClassAssertionStatus(java.lang.String, boolean) , setDefaultAssertionStatus sample code for java.lang.ClassLoader.setDefaultAssertionStatus(boolean) definition code for java.lang.ClassLoader.setDefaultAssertionStatus(boolean) , setPackageAssertionStatus sample code for java.lang.ClassLoader.setPackageAssertionStatus(java.lang.String, boolean) definition code for java.lang.ClassLoader.setPackageAssertionStatus(java.lang.String, boolean) , setSigners sample code for java.lang.ClassLoader.setSigners(java.lang.Class, java.lang.Object[]) definition code for java.lang.ClassLoader.setSigners(java.lang.Class, java.lang.Object[])
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

URLClassLoader sample code for java.net.URLClassLoader(java.net.URL[], java.lang.ClassLoader) definition code for java.net.URLClassLoader(java.net.URL[], java.lang.ClassLoader)

public URLClassLoader(URL sample code for java.net.URL definition code for java.net.URL [] urls,
                      ClassLoader sample code for java.lang.ClassLoader definition code for java.lang.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 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.

If there is a security manager, this method first calls the security manager's checkCreateClassLoader method to ensure creation of a class loader is allowed.

Parameters:
urls - the URLs from which to load classes and resources
parent - the parent class loader for delegation
Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkCreateClassLoader method doesn't allow creation of a class loader.
See Also:
SecurityManager.checkCreateClassLoader() sample code for java.lang.SecurityManager.checkCreateClassLoader() definition code for java.lang.SecurityManager.checkCreateClassLoader()

URLClassLoader sample code for java.net.URLClassLoader(java.net.URL[]) definition code for java.net.URLClassLoader(java.net.URL[])

public URLClassLoader(URL sample code for java.net.URL definition code for java.net.URL [] urls)
Constructs a new URLClassLoader for the specified URLs using the default delegation parent ClassLoader. 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.

If there is a security manager, this method first calls the security manager's checkCreateClassLoader method to ensure creation of a class loader is allowed.

Parameters:
urls - the URLs from which to load classes and resources
Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkCreateClassLoader method doesn't allow creation of a class loader.
See Also:
SecurityManager.checkCreateClassLoader() sample code for java.lang.SecurityManager.checkCreateClassLoader() definition code for java.lang.SecurityManager.checkCreateClassLoader()

URLClassLoader sample code for java.net.URLClassLoader(java.net.URL[], java.lang.ClassLoader, java.net.URLStreamHandlerFactory) definition code for java.net.URLClassLoader(java.net.URL[], java.lang.ClassLoader, java.net.URLStreamHandlerFactory)

public URLClassLoader(URL sample code for java.net.URL definition code for java.net.URL [] urls,
                      ClassLoader sample code for java.lang.ClassLoader definition code for java.lang.ClassLoader  parent,
                      URLStreamHandlerFactory sample code for java.net.URLStreamHandlerFactory definition code for java.net.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 URLs.

If there is a security manager, this method first calls the security manager's checkCreateClassLoader method to ensure creation of a class loader is allowed.

Parameters:
urls - the URLs from which to load classes and resources
parent - the parent class loader for delegation
factory - the URLStreamHandlerFactory to use when creating URLs
Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkCreateClassLoader method doesn't allow creation of a class loader.
See Also:
SecurityManager.checkCreateClassLoader() sample code for java.lang.SecurityManager.checkCreateClassLoader() definition code for java.lang.SecurityManager.checkCreateClassLoader()
Method Detail

addURL sample code for java.net.URLClassLoader.addURL(java.net.URL) definition code for java.net.URLClassLoader.addURL(java.net.URL)

protected void addURL(URL sample code for java.net.URL definition code for java.net.URL  url)
Appends the specified URL to the list of URLs to search for classes and resources.

Parameters:
url - the URL to be added to the search path of URLs

getURLs sample code for java.net.URLClassLoader.getURLs() definition code for java.net.URLClassLoader.getURLs()

public URL sample code for java.net.URL definition code for java.net.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.

Returns:
the search path of URLs for loading classes and resources.

findClass sample code for java.net.URLClassLoader.findClass(java.lang.String) definition code for java.net.URLClassLoader.findClass(java.lang.String)

protected Class sample code for java.lang.Class definition code for java.lang.Class <?> findClass(String sample code for java.lang.String definition code for java.lang.String  name)
                      throws ClassNotFoundException sample code for java.lang.ClassNotFoundException definition code for java.lang.ClassNotFoundException 
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.

Overrides:
findClass sample code for java.lang.ClassLoader.findClass(java.lang.String) definition code for java.lang.ClassLoader.findClass(java.lang.String) in class ClassLoader sample code for java.lang.ClassLoader definition code for java.lang.ClassLoader
Parameters:
name - the name of the class
Returns:
the resulting class
Throws:
ClassNotFoundException sample code for java.lang.ClassNotFoundException definition code for java.lang.ClassNotFoundException - if the class could not be found

definePackage sample code for java.net.URLClassLoader.definePackage(java.lang.String, java.util.jar.Manifest, java.net.URL) definition code for java.net.URLClassLoader.definePackage(java.lang.String, java.util.jar.Manifest, java.net.URL)

protected Package sample code for java.lang.Package definition code for java.lang.Package  definePackage(String sample code for java.lang.String definition code for java.lang.String  name,
                                Manifest sample code for java.util.jar.Manifest definition code for java.util.jar.Manifest  man,
                                URL sample code for java.net.URL definition code for java.net.URL  url)
                         throws IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException 
Defines a new package by name in this ClassLoader. The attributes contained in the specified Manifest will be used to obtain package version and sealing information. For sealed packages, the additional URL specifies the code source URL from which the package was loaded.

Parameters:
name - the package name
man - the Manifest containing package version and sealing information
url - the code source url for the package, or null if none
Returns:
the newly defined Package object
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the package name duplicates an existing package either in this class loader or one of its ancestors

findResource sample code for java.net.URLClassLoader.findResource(java.lang.String) definition code for java.net.URLClassLoader.findResource(java.lang.String)

public URL sample code for java.net.URL definition code for java.net.URL  findResource(String sample code for java.lang.String definition code for java.lang.String  name)
Finds the resource with the specified name on the URL search path.

Overrides:
findResource sample code for java.lang.ClassLoader.findResource(java.lang.String) definition code for java.lang.ClassLoader.findResource(java.lang.String) in class ClassLoader sample code for java.lang.ClassLoader definition code for java.lang.ClassLoader
Parameters:
name - the name of the resource
Returns:
a URL for the resource, or null if the resource could not be found.

findResources sample code for java.net.URLClassLoader.findResources(java.lang.String) definition code for java.net.URLClassLoader.findResources(java.lang.String)

public Enumeration sample code for java.util.Enumeration definition code for java.util.Enumeration <URL sample code for java.net.URL definition code for java.net.URL > findResources(String sample code for java.lang.String definition code for java.lang.String  name)
                               throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Returns an Enumeration of URLs representing all of the resources on the URL search path having the specified name.

Overrides:
findResources sample code for java.lang.ClassLoader.findResources(java.lang.String) definition code for java.lang.ClassLoader.findResources(java.lang.String) in class ClassLoader sample code for java.lang.ClassLoader definition code for java.lang.ClassLoader
Parameters:
name - the resource name
Returns:
an Enumeration of URLs
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O exception occurs

getPermissions sample code for java.net.URLClassLoader.getPermissions(java.security.CodeSource) definition code for java.net.URLClassLoader.getPermissions(java.security.CodeSource)

protected PermissionCollection sample code for java.security.PermissionCollection definition code for java.security.PermissionCollection  getPermissions(CodeSource sample code for java.security.CodeSource definition code for java.security.CodeSource  codesource)
Returns the permissions for the given codesource object. The implementation of this method first calls super.getPermissions and then adds permissions based on the URL of the codesource.

If the protocol is "file" and the path specifies a file, then permission to read that file is granted. If protocol is "file" and the path is a directory, permission is granted to read all files and (recursively) all files and subdirectories contained in that directory.

If the protocol is not "file", then to connect to and accept connections from the URL's host is granted.

Overrides:
getPermissions sample code for java.security.SecureClassLoader.getPermissions(java.security.CodeSource) definition code for java.security.SecureClassLoader.getPermissions(java.security.CodeSource) in class SecureClassLoader sample code for java.security.SecureClassLoader definition code for java.security.SecureClassLoader
Parameters:
codesource - the codesource
Returns:
the permissions granted to the codesource

newInstance sample code for java.net.URLClassLoader.newInstance(java.net.URL[], java.lang.ClassLoader) definition code for java.net.URLClassLoader.newInstance(java.net.URL[], java.lang.ClassLoader)

public static URLClassLoader sample code for java.net.URLClassLoader definition code for java.net.URLClassLoader  newInstance(URL sample code for java.net.URL definition code for java.net.URL [] urls,
                                         ClassLoader sample code for java.lang.ClassLoader definition code for java.lang.ClassLoader  parent)
Creates a new instance of URLClassLoader for the specified URLs and parent class loader. If a security manager is installed, the loadClass method of the URLClassLoader returned by this method will invoke the SecurityManager.checkPackageAccess method before loading the class.

Parameters:
urls - the URLs to search for classes and resources
parent - the parent class loader for delegation
Returns:
the resulting class loader

newInstance sample code for java.net.URLClassLoader.newInstance(java.net.URL[]) definition code for java.net.URLClassLoader.newInstance(java.net.URL[])

public static URLClassLoader sample code for java.net.URLClassLoader definition code for java.net.URLClassLoader  newInstance(URL sample code for java.net.URL definition code for java.net.URL [] urls)
Creates a new instance of URLClassLoader for the specified URLs and default parent class loader. If a security manager is installed, the loadClass method of the URLClassLoader returned by this method will invoke the SecurityManager.checkPackageAccess before loading the class.

Parameters:
urls - the URLs to search for classes and resources
Returns:
the resulting class loader