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

public class JNLPClassLoader extends URLClassLoader
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
  • Constructor Details

    • JNLPClassLoader

      public JNLPClassLoader(JNLPFile file, UpdatePolicy policy) throws LaunchException
      Create a new JNLPClassLoader from the specified file.
      Parameters:
      file - the JNLP file
      policy - 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 for
      policy - the update policy to use when downloading resources
      enableCodeBase - 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

      public void setApplication(ApplicationInstance app)
      Sets the JNLP app this group is for; can only be called once.
      Parameters:
      app - application to be ser to this group
    • getApplication

      public ApplicationInstance getApplication()
      Returns:
      the JNLP app for this classloader
    • getJNLPFile

      public JNLPFile getJNLPFile()
      Returns:
      the JNLP file the classloader was created from.
    • getPermissions

      public PermissionCollection getPermissions(CodeSource cs)
      Returns the permissions for the CodeSource.
      Overrides:
      getPermissions in class URLClassLoader
    • addPermission

      public void addPermission(Permission p)
    • findLibrary

      protected String findLibrary(String lib)
      Return the absolute path to the native library.
      Overrides:
      findLibrary in class ClassLoader
    • loadClass

      public Class<?> loadClass(String name) throws ClassNotFoundException
      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.html

      Affected fields: available, classpaths, jarIndexes, jarEntries, jarLocationSecurityMap

      Overrides:
      loadClass in class ClassLoader
      Throws:
      ClassNotFoundException
    • findClass

      protected Class<?> findClass(String name) throws ClassNotFoundException
      Find the class in this loader or any of its extension loaders.
      Overrides:
      findClass in class URLClassLoader
      Throws:
      ClassNotFoundException
    • findResource

      public URL findResource(String name)
      Finds the resource in this, the parent, or the extension class loaders.
      Overrides:
      findResource in class URLClassLoader
      Returns:
      a URL for the resource, or null if the resource could not be found.
    • findResources

      public Enumeration<URL> findResources(String name) throws IOException
      Find the resources in this, the parent, or the extension class loaders. Load lazy resources if not found in current resources.
      Overrides:
      findResources in class URLClassLoader
      Throws:
      IOException
    • getSigning

      public boolean getSigning()
    • getSecurity

      public SecurityDesc getSecurity()
    • getMainClass

      public String getMainClass()
    • getTracker

      public ResourceTracker getTracker()
    • getMainClassNameFromManifest

      public String getMainClassNameFromManifest(JARDesc mainJarDesc) throws IOException
      Throws:
      IOException