Class JNLPClassLoader
java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
net.sourceforge.jnlp.runtime.classloader.JNLPClassLoader
- All Implemented Interfaces:
Closeable,AutoCloseable
Classloader that takes it's resources from a JNLP file. If the JNLP file
defines extensions, separate classloaders for these will be created
automatically. Classes are loaded with the security context when the
classloader was created.
- Version:
- $Revision: 1.20 $
- Author:
- Jon A. Maxwell (JAM) - initial author
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceJNLPClassLoader.ExceptionalSupplier<T,E extends Exception> static enum -
Constructor Summary
ConstructorsConstructorDescriptionJNLPClassLoader(JNLPFile file, UpdatePolicy policy) Create a new JNLPClassLoader from the specified file. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidAdd applet's codebase URL.protected Class<?> Find the class in this loader or any of its extension loaders.protected StringfindLibrary(String lib) Return the absolute path to the native library.findResource(String name) Finds the resource in this, the parent, or the extension class loaders.findResources(String name) Find the resources in this, the parent, or the extension class loaders.static JNLPClassLoadergetInstance(JNLPFile file, UpdatePolicy policy, boolean enableCodeBase) Returns a JNLP classloader for the specified JNLP file.getMainClassNameFromManifest(JARDesc mainJarDesc) Returns the permissions for the CodeSource.booleanClass<?> Find a JAR in the shared 'extension' classloaders, this classloader, or one of the classloaders for the JNLP file's extensions.voidSets the JNLP app this group is for; can only be called once.Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, getResourceAsStream, getURLs, newInstance, newInstanceMethods inherited from class java.security.SecureClassLoader
defineClass, defineClassMethods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Constructor Details
-
JNLPClassLoader
Create a new JNLPClassLoader from the specified file.- Parameters:
file- the JNLP filepolicy- update policy of loader- Throws:
LaunchException- if app can not be loaded
-
-
Method Details
-
getInstance
public static JNLPClassLoader getInstance(JNLPFile file, UpdatePolicy policy, boolean enableCodeBase) throws LaunchException Returns a JNLP classloader for the specified JNLP file.- Parameters:
file- the file to load classes forpolicy- the update policy to use when downloading resourcesenableCodeBase- true if codebase can be searched (ok for applets,false for apps)- Returns:
- existing classloader. creates new if none reliable exists
- Throws:
LaunchException- when launch is doomed
-
enableCodeBase
public void enableCodeBase()Add applet's codebase URL. This allows compatibility with applets that load resources from their codebase instead of through JARs, but can slow down resource loading. Resources loaded from the codebase are not cached. -
setApplication
Sets the JNLP app this group is for; can only be called once.- Parameters:
app- application to be ser to this group
-
getApplication
- Returns:
- the JNLP app for this classloader
-
getJNLPFile
- Returns:
- the JNLP file the classloader was created from.
-
getPermissions
Returns the permissions for the CodeSource.- Overrides:
getPermissionsin classURLClassLoader
-
addPermission
-
findLibrary
Return the absolute path to the native library.- Overrides:
findLibraryin classClassLoader
-
loadClass
Find a JAR in the shared 'extension' classloaders, this classloader, or one of the classloaders for the JNLP file's extensions. This method used to be qualified "synchronized." This was done solely for the purpose of ensuring only one thread entered the method at a time. This was not strictly necessary - ensuring that all affected fields are thread-safe is sufficient. Locking on the JNLPClassLoader instance when this method is called can result in deadlock if another thread is dealing with the CodebaseClassLoader at the same time. This solution is very heavy-handed as the instance lock is not truly required, and taking the lock on the classloader instance when not needed is not in general a good idea because it can and will lead to deadlock when multithreaded classloading is in effect. The solution is to keep the fields thread safe on their own. This is accomplished by wrapping them in Collections.synchronized* to provide atomic add/remove operations, and synchronizing on them when iterating or performing multiple mutations. See bug report RH976833. On some systems this bug will manifest itself as deadlock on every webpage with more than one Java applet, potentially also causing the browser process to hang. More information in the mailing list archives: http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2013-September/024536.htmlAffected fields: available, classpaths, jarIndexes, jarEntries, jarLocationSecurityMap
- Overrides:
loadClassin classClassLoader- Throws:
ClassNotFoundException
-
findClass
Find the class in this loader or any of its extension loaders.- Overrides:
findClassin classURLClassLoader- Throws:
ClassNotFoundException
-
findResource
Finds the resource in this, the parent, or the extension class loaders.- Overrides:
findResourcein classURLClassLoader- Returns:
- a
URLfor the resource, ornullif the resource could not be found.
-
findResources
Find the resources in this, the parent, or the extension class loaders. Load lazy resources if not found in current resources.- Overrides:
findResourcesin classURLClassLoader- Throws:
IOException
-
getSigning
public boolean getSigning() -
getSecurity
-
getMainClass
-
getTracker
-
getMainClassNameFromManifest
- Throws:
IOException
-