java.net.URLClassLoader
This class loader is responsible for loading classes and resources from a
list of URLs which can refer to either directories or JAR files. Classes
loaded by this URLClassLoader
are granted permission to access
the URLs contained in the URL search list.
Summary
Public Constructors
Public Methods
Protected Methods
clearAssertionStatus,
defineClass,
defineClass,
defineClass,
defineClass,
definePackage,
findClass,
findLibrary,
findLoadedClass,
findResource,
findResources,
findSystemClass,
getPackage,
getPackages,
getParent,
getResource,
getResourceAsStream,
getResources,
getSystemClassLoader,
getSystemResource,
getSystemResourceAsStream,
getSystemResources,
loadClass,
loadClass,
resolveClass,
setClassAssertionStatus,
setDefaultAssertionStatus,
setPackageAssertionStatus,
setSigners
|
|
|
|
|
void |
clearAssertionStatus() |
|
|
final |
|
|
Class<?> |
defineClass(byte[] classRep, int offset, int length) |
|
|
final |
|
|
Class<?> |
defineClass(String name, ByteBuffer b, ProtectionDomain protectionDomain) |
|
|
final |
|
|
Class<?> |
defineClass(String className, byte[] classRep, int offset, int length, ProtectionDomain protectionDomain) |
|
|
final |
|
|
Class<?> |
defineClass(String className, byte[] classRep, int offset, int length) |
|
|
|
|
|
Package |
definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) |
|
|
|
|
|
Class<?> |
findClass(String className) |
|
|
|
|
|
String |
findLibrary(String libName) |
|
|
final |
|
|
Class<?> |
findLoadedClass(String className) |
|
|
|
|
|
URL |
findResource(String resName) |
|
|
|
|
|
Enumeration<URL> |
findResources(String resName) |
|
|
final |
|
|
Class<?> |
findSystemClass(String className) |
|
|
|
|
|
Package |
getPackage(String name) |
|
|
|
|
|
Package[] |
getPackages() |
|
|
final |
|
|
ClassLoader |
getParent() |
|
|
|
|
|
URL |
getResource(String resName) |
|
|
|
|
|
InputStream |
getResourceAsStream(String resName) |
|
|
|
|
|
Enumeration<URL> |
getResources(String resName) |
|
|
|
static |
|
ClassLoader |
getSystemClassLoader() |
|
|
|
static |
|
URL |
getSystemResource(String resName) |
|
|
|
static |
|
InputStream |
getSystemResourceAsStream(String resName) |
|
|
|
static |
|
Enumeration<URL> |
getSystemResources(String resName) |
|
|
|
|
|
Class<?> |
loadClass(String className) |
|
|
|
|
|
Class<?> |
loadClass(String className, boolean resolve) |
|
|
final |
|
|
void |
resolveClass(Class<?> clazz) |
|
|
|
|
|
void |
setClassAssertionStatus(String cname, boolean enable) |
|
|
|
|
|
void |
setDefaultAssertionStatus(boolean enable) |
|
|
|
|
|
void |
setPackageAssertionStatus(String pname, boolean enable) |
|
|
final |
|
|
void |
setSigners(Class<?> c, Object[] signers) |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Public Constructors
public
URLClassLoader(URL[] urls)
Constructs a new instance of this class. The newly created instance will
have the system ClassLoader as its parent. URLs that end with "/" are
assumed to be directories, otherwise they are assumed to be Jar files.
Throws
SecurityException
| if a security manager exists and its checkCreateClassLoader
method doesn't allow creation of new ClassLoaders
|
public
URLClassLoader(URL[] urls, ClassLoader parent)
Constructs a new instance of this class. The newly created instance will
have the specified ClassLoader as its parent. URLs that end with "/" are
assumed to be directories, otherwise they are assumed to be Jar files.
Parameters
urls
| the URLs to search |
parent
| the ClassLoader to assign as this loader's parent. |
Throws
SecurityException
| if a security manager exists and its checkCreateClassLoader
method doesn't allow creation of new ClassLoaders
|
Constructs a new instance of this class. The newly created instance will
have the specified ClassLoader as its parent and use the specified
factory to create stream handlers. URLs that end with "/" are assumed to
be directories, otherwise they are assumed to be Jar files.
Parameters
searchUrls
| java.net.URL[] the URLs that will be searched in the order
they were specified for resource |
parent
| ClassLoader the ClassLoader name of the resource to find. |
factory
| java.net.URLStreamHandlerFactory the factory that will used to
create stream (protocol) handlers |
Throws
SecurityException
| if a security manager exists and its checkCreateClassLoader
method doesn't allow creation of new ClassLoaders
|
Public Methods
public
URL
findResource(String name)
Returns a URL referencing the specified resource or null if no resource
could be found.
Parameters
name
| java.lang.String the name of the requested resource
|
Returns
- URL URL for the resource.
Returns an enumeration of URLs that contain the specified resource.
Parameters
name
| java.lang.String the name of the requested resource |
Returns
- Enumeration the enumeration of URLs that contain the specified
resource.
Throws
IOException
| thrown if an IO Exception occurs while attempting to connect
|
public
URL[]
getURLs()
Returns the search list of this URLClassLoader
Returns an instance of
URLClassLoader
.
loadClass()
of the new instance will call security
manager's
checkPackageAccess()
before loading a class.
Parameters
urls
| URL[] the list of URLs that is passed to the new
URLClassloader |
parentCl
| ClassLoader the parent class loader that is passed to the new
URLClassloader
|
Returns
- URLClassLoader the new instance of
URLClassLoader
Returns an instance of
URLClassLoader
.
loadClass()
of the new instance will call the
SecurityManager's
checkPackageAccess()
before loading a
class.
Parameters
urls
| java.net.URL[] a list of URLs that is passed to the new
URLClassloader
|
Returns
- java.net.URLClassLoader the new instance of
URLClassLoader
Protected Methods
protected
void
addURL(URL url)
Adds the specified URL to the search list.
Parameters
url
| java.net.URL the new URL
|
protected
Package
definePackage(String packageName, Manifest manifest, URL url)
Define a new Package using information extracted from the specified
Manifest.
Parameters
packageName
| The name of the package |
manifest
| The Manifest for the Package |
url
| The code source for the Package |
protected
Class<?>
findClass(String clsName)
Locates and loads the specified class, searching this URLClassLoader's
list of URLS.
Parameters
clsName
| String the name of the class. |
Returns
- Class the class that has been loaded.
Returns the permissions for the given code source. First this method
retrieves the permissions from the system policy. If the protocol is
"file:/" then a new permission,
FilePermission
, granting
the read permission to the file is added to the permission collection.
Otherwise, connecting to and accepting connections from the URL is
granted.