Class WebAppClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- java.net.URLClassLoader
-
- org.eclipse.jetty.webapp.WebAppClassLoader
-
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
CachingWebAppClassLoader
public class WebAppClassLoader extends URLClassLoader
ClassLoader for HttpContext.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 withWebAppContext.isServerClass(String)andWebAppContext.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceWebAppClassLoader.ContextThe Context in which the classloader operates.
-
Constructor Summary
Constructors Constructor Description WebAppClassLoader(ClassLoader parent, WebAppClassLoader.Context context)Constructor.WebAppClassLoader(WebAppClassLoader.Context context)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddClassFileTransformer(ClassFileTransformer transformer)Deprecated.voidaddClassPath(String classPath)voidaddClassPath(org.eclipse.jetty.util.resource.Resource resource)voidaddJars(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.voidaddTransformer(ClassFileTransformer transformer)voidclose()protected Class<?>findClass(String name)protected Class<?>foundClass(String name, URL url)WebAppClassLoader.ContextgetContext()StringgetName()PermissionCollectiongetPermissions(CodeSource cs)URLgetResource(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)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<?>loadClass(String name, boolean resolve)booleanremoveClassFileTransformer(ClassFileTransformer transformer)Deprecated.useremoveTransformer(ClassFileTransformer)insteadbooleanremoveTransformer(ClassFileTransformer transformer)static <T> TrunWithServerClassAccess(PrivilegedExceptionAction<T> action)Run an action with access to ServerClassesvoidsetName(String name)StringtoString()-
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 Detail
-
WebAppClassLoader
public WebAppClassLoader(WebAppClassLoader.Context context) throws IOException
Constructor.- Parameters:
context- the context for this classloader- Throws:
IOException- if unable to initialize from context
-
WebAppClassLoader
public WebAppClassLoader(ClassLoader parent, WebAppClassLoader.Context context) throws IOException
Constructor.- Parameters:
parent- the parent classloadercontext- the context for this classloader- Throws:
IOException- if unable to initialize classloader
-
-
Method Detail
-
runWithServerClassAccess
public static <T> T runWithServerClassAccess(PrivilegedExceptionAction<T> action) throws Exception
Run an action with access to ServerClassesRun the passed
PrivilegedExceptionActionwith the classloader configured so as to allow server classes to be visible- Type Parameters:
T- The type returned by the action- Parameters:
action- The action to run- Returns:
- The return from the action
- Throws:
Exception- if thrown by the action
-
getName
public String getName()
- Overrides:
getNamein classClassLoader- Returns:
- the name of the classloader
-
setName
public void setName(String name)
- Parameters:
name- the name of the classloader
-
getContext
public WebAppClassLoader.Context getContext()
-
addClassPath
public void addClassPath(org.eclipse.jetty.util.resource.Resource resource) throws IOException- 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
public void addClassPath(String classPath) throws IOException
- 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
public PermissionCollection getPermissions(CodeSource cs)
- Overrides:
getPermissionsin classURLClassLoader
-
getResources
public Enumeration<URL> getResources(String name) throws IOException
- Overrides:
getResourcesin classClassLoader- Throws:
IOException
-
getResource
public 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. This is non-standard and it is recommended to not rely on this behavior- Overrides:
getResourcein classClassLoader
-
loadClass
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
- Overrides:
loadClassin classClassLoader- Throws:
ClassNotFoundException
-
addClassFileTransformer
@Deprecated public void addClassFileTransformer(ClassFileTransformer transformer)
Deprecated.- Parameters:
transformer- the transformer to add
-
removeClassFileTransformer
@Deprecated public boolean removeClassFileTransformer(ClassFileTransformer transformer)
Deprecated.useremoveTransformer(ClassFileTransformer)instead- Parameters:
transformer- the transformer to remove- Returns:
- true if transformer was removed
-
addTransformer
public void addTransformer(ClassFileTransformer transformer)
-
removeTransformer
public boolean removeTransformer(ClassFileTransformer transformer)
-
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
-
findClass
protected Class<?> findClass(String name) throws ClassNotFoundException
- Overrides:
findClassin classURLClassLoader- Throws:
ClassNotFoundException
-
foundClass
protected Class<?> foundClass(String name, URL url) throws ClassNotFoundException
- Throws:
ClassNotFoundException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classURLClassLoader- Throws:
IOException
-
-