Class WebAppClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- java.net.URLClassLoader
-
- org.eclipse.jetty.webapp.WebAppClassLoader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,org.eclipse.jetty.util.ClassVisibilityChecker
- Direct Known Subclasses:
CachingWebAppClassLoader
public class WebAppClassLoader extends java.net.URLClassLoader implements org.eclipse.jetty.util.ClassVisibilityCheckerClassLoader 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(java.lang.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(java.lang.instrument.ClassFileTransformer transformer)Deprecated.voidaddClassPath(java.lang.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(java.lang.instrument.ClassFileTransformer transformer)voidclose()protected java.lang.Class<?>findClass(java.lang.String name)protected java.lang.Class<?>foundClass(java.lang.String name, java.net.URL url)WebAppClassLoader.ContextgetContext()java.lang.StringgetName()java.security.PermissionCollectiongetPermissions(java.security.CodeSource cs)java.net.URLgetResource(java.lang.String name)Get a resource from the classloader NOTE: this method provides a convenience of hacking off a leading / should one be present.java.util.Enumeration<java.net.URL>getResources(java.lang.String name)booleanisServerClass(java.lang.Class<?> clazz)booleanisSystemClass(java.lang.Class<?> clazz)protected java.lang.Class<?>loadAsResource(java.lang.String name, boolean checkSystemResource)Look for the classname as a resource to avoid loading a class that is potentially a system resource.protected java.lang.Class<?>loadClass(java.lang.String name, boolean resolve)booleanremoveClassFileTransformer(java.lang.instrument.ClassFileTransformer transformer)Deprecated.useremoveTransformer(ClassFileTransformer)insteadbooleanremoveTransformer(java.lang.instrument.ClassFileTransformer transformer)static <T> TrunWithServerClassAccess(java.security.PrivilegedExceptionAction<T> action)Run an action with access to ServerClassesvoidsetName(java.lang.String name)java.lang.StringtoString()-
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findResource, findResources, getResourceAsStream, getURLs, newInstance, newInstance
-
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 java.io.IOException
Constructor.- Parameters:
context- the context for this classloader- Throws:
java.io.IOException- if unable to initialize from context
-
WebAppClassLoader
public WebAppClassLoader(java.lang.ClassLoader parent, WebAppClassLoader.Context context) throws java.io.IOExceptionConstructor.- Parameters:
parent- the parent classloadercontext- the context for this classloader- Throws:
java.io.IOException- if unable to initialize classloader
-
-
Method Detail
-
runWithServerClassAccess
public static <T> T runWithServerClassAccess(java.security.PrivilegedExceptionAction<T> action) throws java.lang.ExceptionRun 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:
java.lang.Exception- if thrown by the action
-
getName
public java.lang.String getName()
- Overrides:
getNamein classjava.lang.ClassLoader- Returns:
- the name of the classloader
-
setName
public void setName(java.lang.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 java.io.IOException- Parameters:
resource- Comma or semicolon separated path of filenames or URLs pointing to directories or jar files. Directories should end with '/'.- Throws:
java.io.IOException- if unable to add classpath from resource
-
addClassPath
public void addClassPath(java.lang.String classPath) throws java.io.IOException- Parameters:
classPath- Comma or semicolon separated path of filenames or URLs pointing to directories or jar files. Directories should end with '/'.- Throws:
java.io.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 java.security.PermissionCollection getPermissions(java.security.CodeSource cs)
- Overrides:
getPermissionsin classjava.net.URLClassLoader
-
getResources
public java.util.Enumeration<java.net.URL> getResources(java.lang.String name) throws java.io.IOException- Overrides:
getResourcesin classjava.lang.ClassLoader- Throws:
java.io.IOException
-
getResource
public java.net.URL getResource(java.lang.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 classjava.lang.ClassLoader
-
loadClass
protected java.lang.Class<?> loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException- Overrides:
loadClassin classjava.lang.ClassLoader- Throws:
java.lang.ClassNotFoundException
-
addClassFileTransformer
@Deprecated public void addClassFileTransformer(java.lang.instrument.ClassFileTransformer transformer)
Deprecated.- Parameters:
transformer- the transformer to add
-
removeClassFileTransformer
@Deprecated public boolean removeClassFileTransformer(java.lang.instrument.ClassFileTransformer transformer)
Deprecated.useremoveTransformer(ClassFileTransformer)instead- Parameters:
transformer- the transformer to remove- Returns:
- true if transformer was removed
-
addTransformer
public void addTransformer(java.lang.instrument.ClassFileTransformer transformer)
-
removeTransformer
public boolean removeTransformer(java.lang.instrument.ClassFileTransformer transformer)
-
loadAsResource
protected java.lang.Class<?> loadAsResource(java.lang.String name, boolean checkSystemResource) throws java.lang.ClassNotFoundExceptionLook 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:
java.lang.ClassNotFoundException- if the class cannot be found
-
findClass
protected java.lang.Class<?> findClass(java.lang.String name) throws java.lang.ClassNotFoundException- Overrides:
findClassin classjava.net.URLClassLoader- Throws:
java.lang.ClassNotFoundException
-
foundClass
protected java.lang.Class<?> foundClass(java.lang.String name, java.net.URL url) throws java.lang.ClassNotFoundException- Throws:
java.lang.ClassNotFoundException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.net.URLClassLoader- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isSystemClass
public boolean isSystemClass(java.lang.Class<?> clazz)
- Specified by:
isSystemClassin interfaceorg.eclipse.jetty.util.ClassVisibilityChecker
-
isServerClass
public boolean isServerClass(java.lang.Class<?> clazz)
- Specified by:
isServerClassin interfaceorg.eclipse.jetty.util.ClassVisibilityChecker
-
-