public class WebAppClassLoader extends URLClassLoader
Specializes URLClassLoader with some utility and file mapping methods.
This loader defaults to the 2.3 servlet spec behavior where non
system classes are loaded from the classpath in preference to the
parent loader. Java2 compliant loading, where the parent loader
always has priority, can be selected with the
WebAppContext.setParentLoaderPriority(boolean)
method and influenced with WebAppContext.isServerClass(String)
and
WebAppContext.isSystemClass(String)
.
If no parent class loader is provided, then the current thread context classloader will be used. If that is null then the classloader that loaded this class is used as the parent.
Modifier and Type | Class and Description |
---|---|
static interface |
WebAppClassLoader.Context
The Context in which the classloader operates.
|
Constructor and Description |
---|
WebAppClassLoader(ClassLoader parent,
WebAppClassLoader.Context context)
Constructor.
|
WebAppClassLoader(WebAppClassLoader.Context context)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addClassFileTransformer(ClassFileTransformer transformer)
Deprecated.
|
void |
addClassPath(Resource resource) |
void |
addClassPath(String classPath) |
void |
addJars(Resource lib)
Add elements to the class path for the context from the jar and zip files found
in the specified resource.
|
void |
addTransformer(ClassFileTransformer transformer) |
void |
close() |
protected Class<?> |
findClass(String name) |
WebAppClassLoader.Context |
getContext() |
String |
getName() |
PermissionCollection |
getPermissions(CodeSource cs) |
URL |
getResource(String name)
Get a resource from the classloader
NOTE: this method provides a convenience of hacking off a leading /
should one be present.
|
Enumeration<URL> |
getResources(String name) |
Class<?> |
loadClass(String name) |
protected Class<?> |
loadClass(String name,
boolean resolve) |
boolean |
removeClassFileTransformer(ClassFileTransformer transformer)
Deprecated.
use
removeTransformer(ClassFileTransformer) instead |
boolean |
removeTransformer(ClassFileTransformer transformer) |
void |
setName(String name) |
String |
toString() |
addURL, definePackage, findResource, findResources, getResourceAsStream, getURLs, newInstance, newInstance
defineClass, defineClass
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
public WebAppClassLoader(WebAppClassLoader.Context context) throws IOException
context
- the context for this classloaderIOException
- if unable to initialize from contextpublic WebAppClassLoader(ClassLoader parent, WebAppClassLoader.Context context) throws IOException
parent
- the parent classloadercontext
- the context for this classloaderIOException
- if unable to initialize classloaderpublic String getName()
public void setName(String name)
name
- the name of the classloaderpublic WebAppClassLoader.Context getContext()
public void addClassPath(Resource resource) throws IOException
resource
- Comma or semicolon separated path of filenames or URLs
pointing to directories or jar files. Directories should end
with '/'.IOException
- if unable to add classpath from resourcepublic void addClassPath(String classPath) throws IOException
classPath
- Comma or semicolon separated path of filenames or URLs
pointing to directories or jar files. Directories should end
with '/'.IOException
- if unable to add classpathpublic void addJars(Resource lib)
lib
- the resource that contains the jar and/or zip files.public PermissionCollection getPermissions(CodeSource cs)
getPermissions
in class URLClassLoader
public Enumeration<URL> getResources(String name) throws IOException
getResources
in class ClassLoader
IOException
public URL getResource(String name)
getResource
in class ClassLoader
public Class<?> loadClass(String name) throws ClassNotFoundException
loadClass
in class ClassLoader
ClassNotFoundException
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
loadClass
in class ClassLoader
ClassNotFoundException
@Deprecated public void addClassFileTransformer(ClassFileTransformer transformer)
addTransformer(ClassFileTransformer)
insteadtransformer
- the transformer to add@Deprecated public boolean removeClassFileTransformer(ClassFileTransformer transformer)
removeTransformer(ClassFileTransformer)
insteadtransformer
- the transformer to removepublic void addTransformer(ClassFileTransformer transformer)
public boolean removeTransformer(ClassFileTransformer transformer)
protected Class<?> findClass(String name) throws ClassNotFoundException
findClass
in class URLClassLoader
ClassNotFoundException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class URLClassLoader
IOException
Copyright © 1995-2016 Webtide. All Rights Reserved.