- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.eclipse.jetty.util.ClassVisibilityChecker
- Direct Known Subclasses:
CachingWebAppClassLoader
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(Class)
and
WebAppContext.isSystemClass(Class)
.
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
The Context in which the classloader operates. -
Constructor Summary
ConstructorsConstructorDescriptionWebAppClassLoader
(ClassLoader parent, WebAppClassLoader.Context context) Constructor.Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addClassPath
(String classPath) void
addClassPath
(org.eclipse.jetty.util.resource.Resource resource) void
addJars
(org.eclipse.jetty.util.resource.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<?>
protected Class<?>
foundClass
(String name, URL url) getName()
getResource
(String name) Get a resource from the classloader NOTE: this method provides a convenience of hacking off a leading / should one be present.getResources
(String name) boolean
isServerClass
(Class<?> clazz) boolean
isSystemClass
(Class<?> clazz) protected Class<?>
loadAsResource
(String name, boolean checkSystemResource) Look for the classname as a resource to avoid loading a class that is potentially a system resource.protected Class<?>
boolean
removeTransformer
(ClassFileTransformer transformer) static <T> T
Run an action with access to ServerClassesvoid
toString()
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findResource, findResources, getResourceAsStream, getURLs, newInstance, newInstance
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getPackage, getPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Constructor Details
-
WebAppClassLoader
Constructor.- Parameters:
context
- the context for this classloader- Throws:
IOException
- if unable to initialize from context
-
WebAppClassLoader
Constructor.- Parameters:
parent
- the parent classloadercontext
- the context for this classloader- Throws:
IOException
- if unable to initialize classloader
-
-
Method Details
-
runWithServerClassAccess
Run an action with access to ServerClassesRun the passed
PrivilegedExceptionAction
with the classloader configured so as to allow server classes to be visible- Type Parameters:
T
- The type returned by the actionT
- the type of PrivilegedExceptionAction- Parameters:
action
- The action to run- Returns:
- The return from the action
- Throws:
Exception
- if thrown by the action
-
getName
- Overrides:
getName
in classClassLoader
- Returns:
- the name of the classloader
-
setName
- Parameters:
name
- the name of the classloader
-
getContext
-
addClassPath
- Parameters:
resource
- Comma or semicolon separated path of filenames or URLs pointing to directories or jar files. Directories should end with '/'.- Throws:
IOException
- if unable to add classpath from resource
-
addClassPath
- Parameters:
classPath
- Comma or semicolon separated path of filenames or URLs pointing to directories or jar files. Directories should end with '/'.- Throws:
IOException
- if unable to add classpath
-
addJars
public void addJars(org.eclipse.jetty.util.resource.Resource lib) Add elements to the class path for the context from the jar and zip files found in the specified resource.- Parameters:
lib
- the resource that contains the jar and/or zip files.
-
getPermissions
- Overrides:
getPermissions
in classURLClassLoader
-
getResources
- Overrides:
getResources
in classClassLoader
- Throws:
IOException
-
getResource
Get a resource from the classloader NOTE: this method provides a convenience of hacking off a leading / should one be present. This is non-standard and it is recommended to not rely on this behavior- Overrides:
getResource
in classClassLoader
-
loadClass
- Overrides:
loadClass
in classClassLoader
- Throws:
ClassNotFoundException
-
addTransformer
-
removeTransformer
-
loadAsResource
protected Class<?> loadAsResource(String name, boolean checkSystemResource) throws ClassNotFoundException Look for the classname as a resource to avoid loading a class that is potentially a system resource.- Parameters:
name
- the name of the class to loadcheckSystemResource
- if true and the class isn't a system class we return it- Returns:
- the loaded class
- Throws:
ClassNotFoundException
- if the class cannot be found
-
findClass
- Overrides:
findClass
in classURLClassLoader
- Throws:
ClassNotFoundException
-
foundClass
- Throws:
ClassNotFoundException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classURLClassLoader
- Throws:
IOException
-
toString
-
isSystemClass
- Specified by:
isSystemClass
in interfaceorg.eclipse.jetty.util.ClassVisibilityChecker
-
isServerClass
- Specified by:
isServerClass
in interfaceorg.eclipse.jetty.util.ClassVisibilityChecker
-