Package net.sf.eBus.util
Class JarFileLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- java.net.URLClassLoader
-
- net.sf.eBus.util.JarFileLoader
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public final class JarFileLoader extends URLClassLoader
This class extendsURLClassLoader, providing the ability to load a class from a Java jar file introduced after JVM starts. This capability is needed by long running Java applications which cannot be restarted but need to access a new jar file dropped into a well-known location. That jar file path may be added to theJarFileLoaderviaaddJar(java.lang.String)and thenpackages()used to determine the newly available packages.- Author:
- Charles Rapp
-
-
Field Summary
Fields Modifier and Type Field Description static StringURL_FORMATPlace the JAR file path within this string to create the JAR URL.
-
Constructor Summary
Constructors Constructor Description JarFileLoader(URL[] urls)Constructs a new JAR class loader for the specified URLs and the defaultClassLoader.JarFileLoader(URL[] urls, ClassLoader parent)Constructs a new JAR class loader for the specified URLs and parent class loader.JarFileLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory)Constructs a new JAR class loader for the specified URLs, parent class loader, and URL stream handler factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddJar(String path)Appends the JAR file path to the URL search list.Package[]packages()Returns all thePackages defined by this class loader and its ancestors.-
Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, 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, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Field Detail
-
URL_FORMAT
public static final String URL_FORMAT
Place the JAR file path within this string to create the JAR URL. The URL format is "jar:file:///<path>!/".- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JarFileLoader
public JarFileLoader(URL[] urls)
Constructs a new JAR class loader for the specified URLs and the defaultClassLoader. The URLs are searched from index zero tourls.length - 1for classes and resources after first delegating the search toparent. Any URL ending in "/" is assumed to refer to a directory. Otherwise, the URL is assumed to be a JAR file which will be downloaded and opened as necessary.- Parameters:
urls- the class and resource load path.- Throws:
SecurityException- if a security manager exists and itscheckCreateClassLoadermethod does not allow creation of a class loader.
-
JarFileLoader
public JarFileLoader(URL[] urls, ClassLoader parent)
Constructs a new JAR class loader for the specified URLs and parent class loader. The URLs are searched from index zero tourls.length - 1for classes and resources after first delegating the search toparent. Any URL ending in "/" is assumed to refer to a directory. Otherwise, the URL is assumed to be a JAR file which will be downloaded and opened as necessary.- Parameters:
urls- the class and resource load path.parent- the delegate parent class loader.- Throws:
SecurityException- if a security manager exists and itscheckCreateClassLoadermethod does not allow creation of a class loader.
-
JarFileLoader
public JarFileLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory)
Constructs a new JAR class loader for the specified URLs, parent class loader, and URL stream handler factory. Theparentargument is the delegate class loader. Thefactoryargument is used to obtain protocol handlers when creating new JAR URLs. The search order is:-
parentdelegate first. -
urlsfrom index zero tourls.length - 1.
- Parameters:
urls- the class and resource load path.parent- the delegate parent class loader.factory- the protocol handler factory.- Throws:
SecurityException- if a security manager exists and itscheckCreateClassLoadermethod does not allow creation of a class loader.
-
-
-
Method Detail
-
packages
public Package[] packages()
Returns all thePackages defined by this class loader and its ancestors.- Returns:
- the class loader packages.
-
addJar
public void addJar(String path) throws IOException
Appends the JAR file path to the URL search list.- Parameters:
path- path to a readable JAR file.- Throws:
FileNotFoundException- ifpathrefers to a non-existent file.IOException- ifpatheither does not refer to a regular file or the file cannot be read.MalformedURLException- ifpathcould not be parsed byURL.
-
-