Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8088712

fx:jar launched JavaFX application fails to load "Installed optional packages" (formerly "standard extensions")

XMLWordPrintable

      We used Ant task "fx:jar" from ant-javafx.jar in JDK 1.7.0_60 to build our JAR file, and launched our application via com.javafx.main.Main.
      Everything worked fine until we added some code in our application that referenced class ZipFileSystem.
      Then we received java.lang.NoClassDefFoundError: com/sun/nio/zipfs/ZipFileSystem.
      Debugging indicated that the ClassLoader could not access any classes in the JAR files in directory jdk1.7.0_60/lib/ext.
      Inspection of source code posted on GrepCode for a prior version of com.javafx.main.Main showed that it sets a custom thread context URLClassLoader prior to loading the application class.
      That custom URLClassLoader has a null parent.

      We implemented a workaround fix in our own derived class of Main with a modified version of method main(), using Reflection to access the various private fields and methods in the parent class.
      In our derived class, prior to when the application class is loaded, we set a thread context URLClassLoader with the same URLs, but with a parent of ZipFileSystem.class.getClassLoader(), which is the extension class loader (Launcher$ExtClassLoader).

      This workaround allowed the application to access the JDK installed optional package zipfs.jar (and presumably the others in the same directory).
      So, a fix might be to change method com.javafx.main.Main.findLaunchMethod(File,String) to call:

      new URLClassLoader( urls, extClassLoader )

      where extClassLoader is an instance of Launcher$ExtClassLoader.

            asemenyuk Alexey Semenyuk
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: