Class java.net.URLClassLoader
java.lang.Object
|
+----java.lang.ClassLoader
|
+----java.security.SecureClassLoader
|
+----java.net.URLClassLoader
- public class URLClassLoader
- extends 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:
- JDK1.2
Constructor Summary
|
URLClassLoader(URL[] urls,
ClassLoader parent)
Constructs a new URLClassLoader for the given URLs.
|
URLClassLoader(URL[] urls)
Constructs a new URLClassLoader for the specified URLs using the
default delegation parent ClassLoader .
|
Method Summary
|
void
|
checkPackageDefinition(String name)
This method can be overridden to throw a SecurityException if the
calling thread is not allowed to define classes in the package
specified by the argument.
|
Package
|
definePackage(String name,
Attributes attr,
URL sealBase)
Defines a package by name in this ClassLoader.
|
static URL
|
fileToURL(File file)
Returns the directory or JAR file URL corresponding to the specified
local file name.
|
Class
|
findLocalClass(String name)
Finds and loads the class with the specified name from the URL search
path.
|
URL
|
getLocalResource(String name)
Finds the resource with the specified name on the URL search path.
|
Enumeration
|
getLocalResources(String name)
Returns an Enumeration of URLs representing all of the resources
on the URL search path having the specified name.
|
String
|
getMainClassName()
Searches the URL class path for the first manifest which defines
a 'Main-Class' main attribute.
|
static URL[]
|
pathToURLs(String path)
Utility method for converting a search path string to an array
of directory and JAR file URLs.
|
Methods inherited from class java.lang.ClassLoader
|
checkPackageAccess, defineClass, defineClass, definePackage, findLoadedClass, findLocalClass, findSystemClass, getBaseClassLoader, getLocalResource, getLocalResources, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setSigners |
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
URLClassLoader
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 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.
- Parameters:
urls
- the URLs from which to load classes and resources
parent
- the parent class loader for delegation
URLClassLoader
public URLClassLoader(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.
- Parameters:
urls
- the URLs from which to load classes and resources
getMainClassName
public String getMainClassName()
- Searches the URL class path for the first manifest which defines
a 'Main-Class' main attribute. Returns the value of the attribute
or null if not found.
findLocalClass
protected Class findLocalClass(String name) throws 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.
- Parameters:
name
- the name of the class
- Returns:
- the resulting class
- Throws:
- ClassNotFoundException - if the class could not be found
- Overrides:
- findLocalClass in class ClassLoader
definePackage
protected Package definePackage(String name,
Attributes attr,
URL sealBase)
- Defines a package by name in this ClassLoader. The specification
and implementation title, name, and vendor is obtained from the
given Attributes object.
- Parameters:
name
- the package name
attr
- the package Attributes
sealBase
- if specified then this package is sealed with respect
to the given code base URL
- Throws:
- IllegalArgumentException - if the package name duplicates an
existing package either in this class loader or the parent
class loader
checkPackageDefinition
protected void checkPackageDefinition(String name) throws SecurityException
- This method can be overridden to throw a SecurityException if the
calling thread is not allowed to define classes in the package
specified by the argument. By default, the calling thread is allowed
to define classes in any package.
- Parameters:
name
- the package name
- Throws:
- SecurityException - if the caller cannot define classes in
the specified package
getLocalResource
public URL getLocalResource(String name)
- Finds the resource with the specified name on the URL search path.
Returns a URL for the resource, or null if the resource could not
be found.
- Parameters:
name
- the name of the resource
- Overrides:
- getLocalResource in class ClassLoader
getLocalResources
public Enumeration getLocalResources(String name) throws IOException
- Returns an Enumeration of URLs representing all of the resources
on the URL search path having the specified name.
- Parameters:
name
- the resource name
- Overrides:
- getLocalResources in class ClassLoader
pathToURLs
public static URL[] pathToURLs(String path)
- Utility method for converting a search path string to an array
of directory and JAR file URLs.
- Parameters:
path
- the search path string
- Returns:
- the resulting array of directory and JAR file URLs
fileToURL
public static URL fileToURL(File file)
- Returns the directory or JAR file URL corresponding to the specified
local file name.
- Parameters:
file
- the File object
- Returns:
- the resulting directory or JAR file URL, or null if unknown
Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.