(JDK 11) Run a JAR Archive through reflection which depends on Libraries
Note: I have very little experience with the Module system introduced in Java 9.
I have a Java Process which should run another Jar file by loading and executing it through reflection.
Note that both Jar files depend on the JavaFX framework which got detached from the JDK in Version 11 and as a result could get loaded a second time.
Here the Original version which worked on JDK version 8:
val ideFile = File(binFolder, "Sk-IDE.jar")
val classLoader = ClassLoader.getSystemClassLoader() as URLClassLoader
val method = URLClassLoader::class.java.getDeclaredMethod("addURL", URL::class.java)
method.isAccessible = true
method.invoke(classLoader, ideFile.toURI().toURL())
val coreManager = Class.forName("com.skide.CoreManager")
val instance = coreManager.newInstance()
coreManager.getDeclaredMethod("bootstrap", Array<String>::class.java).invoke(instance, State.args)
(The Reflective call to addURL was necessary because otherwise the loader Jar was unable to load its fxml files)
This approach throws this Exception on JDK 11:
java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')
The approach to create a new URLClassLoader
:
val child = URLClassLoader(arrayOf(URL(ideFile.toURI().toURL().toString())), Installer::class.java.classLoader)
val coreManager = Class.forName("com.skide.CoreManager", true, child)
val instance = coreManager.newInstance()
Platform.runLater {
coreManager.getDeclaredMethod("bootstrap", Array<String>::class.java).invoke(instance, State.args)
}
Throws a JavaFX related Exception:
Exception in thread "JavaFX Application Thread" [20.11.2018 20:13:41 | ERROR] java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
[20.11.2018 20:13:41 | ERROR] at java.base/java.security.AccessController.doPrivileged(Native Method)
[20.11.2018 20:13:41 | ERROR] at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
[20.11.2018 20:13:41 | ERROR] at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
[20.11.2018 20:13:41 | ERROR] at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
[20.11.2018 20:13:41 | ERROR] at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
[20.11.2018 20:13:41 | ERROR] at java.base/java.lang.Thread.run(Thread.java:834)
[20.11.2018 20:13:41 | ERROR] Caused by: java.lang.reflect.InvocationTargetException
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[20.11.2018 20:13:41 | ERROR] at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[20.11.2018 20:13:41 | ERROR] at com.skide.installer.Installer$start$2$1$1.run(Installer.kt:249)
[20.11.2018 20:13:41 | ERROR] at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
[20.11.2018 20:13:41 | ERROR] ... 6 more
[20.11.2018 20:13:41 | ERROR] Caused by: javafx.fxml.LoadException:
unknown path:9
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:105)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:930)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:980)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:227)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:752)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2450)
[20.11.2018 20:13:41 | ERROR] at com.skide.CoreManager$bootstrap$1.invoke(CoreManager.kt:47)
[20.11.2018 20:13:41 | ERROR] at com.skide.CoreManager$bootstrap$1.invoke(CoreManager.kt:24)
[20.11.2018 20:13:41 | ERROR] at com.skide.CoreManager.bootstrap(CoreManager.kt:136)
[20.11.2018 20:13:41 | ERROR] ... 12 more
[20.11.2018 20:13:41 | ERROR] Caused by: java.lang.ClassNotFoundException: com.skide.gui.controllers.SplashGuiController
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
[20.11.2018 20:13:41 | ERROR] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:928)
[20.11.2018 20:13:41 | ERROR] ... 21 more
Whats the best way to solve this?
Regards,
Liz3
EDIT
With the help of xtratic, the solution was actually straight forward:
I simply added the child
URLClassloader to the CoreManager#bootstrap reflective call, the bootstrap method of the CoreManager(loaded jar) than passes that URLClassloader to all FXML loaders.
java javafx kotlin
add a comment |
Note: I have very little experience with the Module system introduced in Java 9.
I have a Java Process which should run another Jar file by loading and executing it through reflection.
Note that both Jar files depend on the JavaFX framework which got detached from the JDK in Version 11 and as a result could get loaded a second time.
Here the Original version which worked on JDK version 8:
val ideFile = File(binFolder, "Sk-IDE.jar")
val classLoader = ClassLoader.getSystemClassLoader() as URLClassLoader
val method = URLClassLoader::class.java.getDeclaredMethod("addURL", URL::class.java)
method.isAccessible = true
method.invoke(classLoader, ideFile.toURI().toURL())
val coreManager = Class.forName("com.skide.CoreManager")
val instance = coreManager.newInstance()
coreManager.getDeclaredMethod("bootstrap", Array<String>::class.java).invoke(instance, State.args)
(The Reflective call to addURL was necessary because otherwise the loader Jar was unable to load its fxml files)
This approach throws this Exception on JDK 11:
java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')
The approach to create a new URLClassLoader
:
val child = URLClassLoader(arrayOf(URL(ideFile.toURI().toURL().toString())), Installer::class.java.classLoader)
val coreManager = Class.forName("com.skide.CoreManager", true, child)
val instance = coreManager.newInstance()
Platform.runLater {
coreManager.getDeclaredMethod("bootstrap", Array<String>::class.java).invoke(instance, State.args)
}
Throws a JavaFX related Exception:
Exception in thread "JavaFX Application Thread" [20.11.2018 20:13:41 | ERROR] java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
[20.11.2018 20:13:41 | ERROR] at java.base/java.security.AccessController.doPrivileged(Native Method)
[20.11.2018 20:13:41 | ERROR] at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
[20.11.2018 20:13:41 | ERROR] at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
[20.11.2018 20:13:41 | ERROR] at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
[20.11.2018 20:13:41 | ERROR] at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
[20.11.2018 20:13:41 | ERROR] at java.base/java.lang.Thread.run(Thread.java:834)
[20.11.2018 20:13:41 | ERROR] Caused by: java.lang.reflect.InvocationTargetException
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[20.11.2018 20:13:41 | ERROR] at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[20.11.2018 20:13:41 | ERROR] at com.skide.installer.Installer$start$2$1$1.run(Installer.kt:249)
[20.11.2018 20:13:41 | ERROR] at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
[20.11.2018 20:13:41 | ERROR] ... 6 more
[20.11.2018 20:13:41 | ERROR] Caused by: javafx.fxml.LoadException:
unknown path:9
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:105)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:930)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:980)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:227)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:752)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2450)
[20.11.2018 20:13:41 | ERROR] at com.skide.CoreManager$bootstrap$1.invoke(CoreManager.kt:47)
[20.11.2018 20:13:41 | ERROR] at com.skide.CoreManager$bootstrap$1.invoke(CoreManager.kt:24)
[20.11.2018 20:13:41 | ERROR] at com.skide.CoreManager.bootstrap(CoreManager.kt:136)
[20.11.2018 20:13:41 | ERROR] ... 12 more
[20.11.2018 20:13:41 | ERROR] Caused by: java.lang.ClassNotFoundException: com.skide.gui.controllers.SplashGuiController
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
[20.11.2018 20:13:41 | ERROR] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:928)
[20.11.2018 20:13:41 | ERROR] ... 21 more
Whats the best way to solve this?
Regards,
Liz3
EDIT
With the help of xtratic, the solution was actually straight forward:
I simply added the child
URLClassloader to the CoreManager#bootstrap reflective call, the bootstrap method of the CoreManager(loaded jar) than passes that URLClassloader to all FXML loaders.
java javafx kotlin
Is that the full stack trace of yourLoadException
?
– xtratic
Nov 20 at 19:09
no, here the full stacktrace: hastebin.com/lesorudewa.cs
– Liz3
Nov 20 at 19:14
Ohhhh... FXML is using the built in classloader to load the FX beans, which of course doesn't know about those classes.
– xtratic
Nov 20 at 19:17
You'll probably need to callFXMLLoader.setClassLoader(urlClassLoader)
– xtratic
Nov 20 at 19:27
add a comment |
Note: I have very little experience with the Module system introduced in Java 9.
I have a Java Process which should run another Jar file by loading and executing it through reflection.
Note that both Jar files depend on the JavaFX framework which got detached from the JDK in Version 11 and as a result could get loaded a second time.
Here the Original version which worked on JDK version 8:
val ideFile = File(binFolder, "Sk-IDE.jar")
val classLoader = ClassLoader.getSystemClassLoader() as URLClassLoader
val method = URLClassLoader::class.java.getDeclaredMethod("addURL", URL::class.java)
method.isAccessible = true
method.invoke(classLoader, ideFile.toURI().toURL())
val coreManager = Class.forName("com.skide.CoreManager")
val instance = coreManager.newInstance()
coreManager.getDeclaredMethod("bootstrap", Array<String>::class.java).invoke(instance, State.args)
(The Reflective call to addURL was necessary because otherwise the loader Jar was unable to load its fxml files)
This approach throws this Exception on JDK 11:
java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')
The approach to create a new URLClassLoader
:
val child = URLClassLoader(arrayOf(URL(ideFile.toURI().toURL().toString())), Installer::class.java.classLoader)
val coreManager = Class.forName("com.skide.CoreManager", true, child)
val instance = coreManager.newInstance()
Platform.runLater {
coreManager.getDeclaredMethod("bootstrap", Array<String>::class.java).invoke(instance, State.args)
}
Throws a JavaFX related Exception:
Exception in thread "JavaFX Application Thread" [20.11.2018 20:13:41 | ERROR] java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
[20.11.2018 20:13:41 | ERROR] at java.base/java.security.AccessController.doPrivileged(Native Method)
[20.11.2018 20:13:41 | ERROR] at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
[20.11.2018 20:13:41 | ERROR] at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
[20.11.2018 20:13:41 | ERROR] at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
[20.11.2018 20:13:41 | ERROR] at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
[20.11.2018 20:13:41 | ERROR] at java.base/java.lang.Thread.run(Thread.java:834)
[20.11.2018 20:13:41 | ERROR] Caused by: java.lang.reflect.InvocationTargetException
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[20.11.2018 20:13:41 | ERROR] at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[20.11.2018 20:13:41 | ERROR] at com.skide.installer.Installer$start$2$1$1.run(Installer.kt:249)
[20.11.2018 20:13:41 | ERROR] at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
[20.11.2018 20:13:41 | ERROR] ... 6 more
[20.11.2018 20:13:41 | ERROR] Caused by: javafx.fxml.LoadException:
unknown path:9
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:105)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:930)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:980)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:227)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:752)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2450)
[20.11.2018 20:13:41 | ERROR] at com.skide.CoreManager$bootstrap$1.invoke(CoreManager.kt:47)
[20.11.2018 20:13:41 | ERROR] at com.skide.CoreManager$bootstrap$1.invoke(CoreManager.kt:24)
[20.11.2018 20:13:41 | ERROR] at com.skide.CoreManager.bootstrap(CoreManager.kt:136)
[20.11.2018 20:13:41 | ERROR] ... 12 more
[20.11.2018 20:13:41 | ERROR] Caused by: java.lang.ClassNotFoundException: com.skide.gui.controllers.SplashGuiController
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
[20.11.2018 20:13:41 | ERROR] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:928)
[20.11.2018 20:13:41 | ERROR] ... 21 more
Whats the best way to solve this?
Regards,
Liz3
EDIT
With the help of xtratic, the solution was actually straight forward:
I simply added the child
URLClassloader to the CoreManager#bootstrap reflective call, the bootstrap method of the CoreManager(loaded jar) than passes that URLClassloader to all FXML loaders.
java javafx kotlin
Note: I have very little experience with the Module system introduced in Java 9.
I have a Java Process which should run another Jar file by loading and executing it through reflection.
Note that both Jar files depend on the JavaFX framework which got detached from the JDK in Version 11 and as a result could get loaded a second time.
Here the Original version which worked on JDK version 8:
val ideFile = File(binFolder, "Sk-IDE.jar")
val classLoader = ClassLoader.getSystemClassLoader() as URLClassLoader
val method = URLClassLoader::class.java.getDeclaredMethod("addURL", URL::class.java)
method.isAccessible = true
method.invoke(classLoader, ideFile.toURI().toURL())
val coreManager = Class.forName("com.skide.CoreManager")
val instance = coreManager.newInstance()
coreManager.getDeclaredMethod("bootstrap", Array<String>::class.java).invoke(instance, State.args)
(The Reflective call to addURL was necessary because otherwise the loader Jar was unable to load its fxml files)
This approach throws this Exception on JDK 11:
java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')
The approach to create a new URLClassLoader
:
val child = URLClassLoader(arrayOf(URL(ideFile.toURI().toURL().toString())), Installer::class.java.classLoader)
val coreManager = Class.forName("com.skide.CoreManager", true, child)
val instance = coreManager.newInstance()
Platform.runLater {
coreManager.getDeclaredMethod("bootstrap", Array<String>::class.java).invoke(instance, State.args)
}
Throws a JavaFX related Exception:
Exception in thread "JavaFX Application Thread" [20.11.2018 20:13:41 | ERROR] java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
[20.11.2018 20:13:41 | ERROR] at java.base/java.security.AccessController.doPrivileged(Native Method)
[20.11.2018 20:13:41 | ERROR] at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
[20.11.2018 20:13:41 | ERROR] at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
[20.11.2018 20:13:41 | ERROR] at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
[20.11.2018 20:13:41 | ERROR] at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
[20.11.2018 20:13:41 | ERROR] at java.base/java.lang.Thread.run(Thread.java:834)
[20.11.2018 20:13:41 | ERROR] Caused by: java.lang.reflect.InvocationTargetException
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[20.11.2018 20:13:41 | ERROR] at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[20.11.2018 20:13:41 | ERROR] at com.skide.installer.Installer$start$2$1$1.run(Installer.kt:249)
[20.11.2018 20:13:41 | ERROR] at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
[20.11.2018 20:13:41 | ERROR] ... 6 more
[20.11.2018 20:13:41 | ERROR] Caused by: javafx.fxml.LoadException:
unknown path:9
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:105)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:930)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:980)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:227)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:752)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2450)
[20.11.2018 20:13:41 | ERROR] at com.skide.CoreManager$bootstrap$1.invoke(CoreManager.kt:47)
[20.11.2018 20:13:41 | ERROR] at com.skide.CoreManager$bootstrap$1.invoke(CoreManager.kt:24)
[20.11.2018 20:13:41 | ERROR] at com.skide.CoreManager.bootstrap(CoreManager.kt:136)
[20.11.2018 20:13:41 | ERROR] ... 12 more
[20.11.2018 20:13:41 | ERROR] Caused by: java.lang.ClassNotFoundException: com.skide.gui.controllers.SplashGuiController
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
[20.11.2018 20:13:41 | ERROR] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
[20.11.2018 20:13:41 | ERROR] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
[20.11.2018 20:13:41 | ERROR] at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:928)
[20.11.2018 20:13:41 | ERROR] ... 21 more
Whats the best way to solve this?
Regards,
Liz3
EDIT
With the help of xtratic, the solution was actually straight forward:
I simply added the child
URLClassloader to the CoreManager#bootstrap reflective call, the bootstrap method of the CoreManager(loaded jar) than passes that URLClassloader to all FXML loaders.
java javafx kotlin
java javafx kotlin
edited Nov 20 at 20:00
asked Nov 20 at 17:27
Liz3
7519
7519
Is that the full stack trace of yourLoadException
?
– xtratic
Nov 20 at 19:09
no, here the full stacktrace: hastebin.com/lesorudewa.cs
– Liz3
Nov 20 at 19:14
Ohhhh... FXML is using the built in classloader to load the FX beans, which of course doesn't know about those classes.
– xtratic
Nov 20 at 19:17
You'll probably need to callFXMLLoader.setClassLoader(urlClassLoader)
– xtratic
Nov 20 at 19:27
add a comment |
Is that the full stack trace of yourLoadException
?
– xtratic
Nov 20 at 19:09
no, here the full stacktrace: hastebin.com/lesorudewa.cs
– Liz3
Nov 20 at 19:14
Ohhhh... FXML is using the built in classloader to load the FX beans, which of course doesn't know about those classes.
– xtratic
Nov 20 at 19:17
You'll probably need to callFXMLLoader.setClassLoader(urlClassLoader)
– xtratic
Nov 20 at 19:27
Is that the full stack trace of your
LoadException
?– xtratic
Nov 20 at 19:09
Is that the full stack trace of your
LoadException
?– xtratic
Nov 20 at 19:09
no, here the full stacktrace: hastebin.com/lesorudewa.cs
– Liz3
Nov 20 at 19:14
no, here the full stacktrace: hastebin.com/lesorudewa.cs
– Liz3
Nov 20 at 19:14
Ohhhh... FXML is using the built in classloader to load the FX beans, which of course doesn't know about those classes.
– xtratic
Nov 20 at 19:17
Ohhhh... FXML is using the built in classloader to load the FX beans, which of course doesn't know about those classes.
– xtratic
Nov 20 at 19:17
You'll probably need to call
FXMLLoader.setClassLoader(urlClassLoader)
– xtratic
Nov 20 at 19:27
You'll probably need to call
FXMLLoader.setClassLoader(urlClassLoader)
– xtratic
Nov 20 at 19:27
add a comment |
1 Answer
1
active
oldest
votes
When you are using the new URLClassLoader
it seems like the method is being invoked but is throwing a javafx.fxml.LoadException
which gets wrapped by the PrivilegedActionException
and InvocationTargetException
.
Even though you load your class with your own URLClassloader
it looks like the FXML parser is trying to load the FX beans with the built-in classloader, which doesn't know about those classes in the FXML.
You'll need to make FXMLLoader use the right classloader that contains all the classes referenced by the fxml. Read the source of FXMLLoader
to get an idea of how it handles classloading. You may need to modify the library doing the fxml loading if possible. Look into FXMLLoader.setClassLoader(urlClassLoader)
or possibly setting a SecurityManager
so that the FXMLLoader
will use the calling classloader.
FXMLLoader.java
/**
* Returns the classloader used by this serializer.
* @since JavaFX 2.1
*/
@CallerSensitive
public ClassLoader getClassLoader() {
if (classLoader == null) {
final SecurityManager sm = System.getSecurityManager();
final Class caller = (sm != null) ?
Reflection.getCallerClass() :
null;
return getDefaultClassLoader(caller);
}
return classLoader;
}
private static ClassLoader getDefaultClassLoader(Class caller) {
if (defaultClassLoader == null) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
final ClassLoader callerClassLoader = (caller != null) ?
caller.getClassLoader() :
null;
if (needsClassLoaderPermissionCheck(callerClassLoader, FXMLLoader.class.getClassLoader())) {
sm.checkPermission(GET_CLASSLOADER_PERMISSION);
}
}
return Thread.currentThread().getContextClassLoader();
}
return defaultClassLoader;
}
I had a guess that Java11 may have changed it's classloader.
See this link (contents pasted below)
Casting To URL Class Loader
Java 9 and the module system improved the platform’s class loading strategy, which is implemented in a new type and in Java 11 the application class loader is of that type. That means it is not aURLClassLoader
, anymore, so the occasional(URLClassLoader) getClass().getClassLoader()
or(URLClassLoader) ClassLoader.getSystemClassLoader()
sequences will no longer execute. This is another typical example where Java 11 is backwards compatible in the strict sense (because that it’s a URLCassLoader was never specified) but which can nonetheless cause migration challenges.
Symptoms
This one is very obvious. You’ll get a ClassCastException complaining that the new AppClassLoader is no URLClassLoader:
Exception in thread "main" java.lang.ClassCastException:
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader
cannot be cast to java.base/java.net.URLClassLoader
at monitor.Main.logClassPathContent(Main.java:46)
at monitor.Main.main(Main.java:28)
Fixes
The class loader was probably cast to access methods specific to URLClassLoader. If so, you might have to face some serious changes.
...
If you’ve used theURLClassLoader
to dynamically load user provided code (for example as part of a plugin infrastructure) by appending to the class path, then you have to find a new way to do that as it can not be done with Java 11. You should instead consider creating a new class loader for that. This has the added advantage that you’ll be able to get rid of the new classes as they are not loaded into the application class loader. You should also read up on layers – they give you a clean abstraction for loading an entirely new module graph.
> "So, correct me if I'm wrong, but it seems like the method is being invoked but is throwing a javafx.fxml.LoadException which gets wrapped by the other two exceptions. My guess is that the new URLClassLoader you create is missing some FXML files that it's trying to load. What is the full stack trace of your LoadException?" - Correct
– Liz3
Nov 20 at 19:11
Did you find which resources it was trying to load, and make sure they are included in your Classloader?
– xtratic
Nov 20 at 19:12
No, since i don´t exactly know how to load them, i am assuming:val child = URLClassLoader( arrayOf(URL(ideFile.toURI().toURL().toString())), Installer::class.java.classLoader)
is loading all classes and resources.
– Liz3
Nov 20 at 19:17
> "You should instead consider creating a new class loader for that." Seams like the best solution
– Liz3
Nov 20 at 19:27
I think you've already covered that part with creating theURLClassLoader
, I think now you just need to set that classloader on yourFXMLLoader
.
– xtratic
Nov 20 at 19:29
|
show 2 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398392%2fjdk-11-run-a-jar-archive-through-reflection-which-depends-on-libraries%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
When you are using the new URLClassLoader
it seems like the method is being invoked but is throwing a javafx.fxml.LoadException
which gets wrapped by the PrivilegedActionException
and InvocationTargetException
.
Even though you load your class with your own URLClassloader
it looks like the FXML parser is trying to load the FX beans with the built-in classloader, which doesn't know about those classes in the FXML.
You'll need to make FXMLLoader use the right classloader that contains all the classes referenced by the fxml. Read the source of FXMLLoader
to get an idea of how it handles classloading. You may need to modify the library doing the fxml loading if possible. Look into FXMLLoader.setClassLoader(urlClassLoader)
or possibly setting a SecurityManager
so that the FXMLLoader
will use the calling classloader.
FXMLLoader.java
/**
* Returns the classloader used by this serializer.
* @since JavaFX 2.1
*/
@CallerSensitive
public ClassLoader getClassLoader() {
if (classLoader == null) {
final SecurityManager sm = System.getSecurityManager();
final Class caller = (sm != null) ?
Reflection.getCallerClass() :
null;
return getDefaultClassLoader(caller);
}
return classLoader;
}
private static ClassLoader getDefaultClassLoader(Class caller) {
if (defaultClassLoader == null) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
final ClassLoader callerClassLoader = (caller != null) ?
caller.getClassLoader() :
null;
if (needsClassLoaderPermissionCheck(callerClassLoader, FXMLLoader.class.getClassLoader())) {
sm.checkPermission(GET_CLASSLOADER_PERMISSION);
}
}
return Thread.currentThread().getContextClassLoader();
}
return defaultClassLoader;
}
I had a guess that Java11 may have changed it's classloader.
See this link (contents pasted below)
Casting To URL Class Loader
Java 9 and the module system improved the platform’s class loading strategy, which is implemented in a new type and in Java 11 the application class loader is of that type. That means it is not aURLClassLoader
, anymore, so the occasional(URLClassLoader) getClass().getClassLoader()
or(URLClassLoader) ClassLoader.getSystemClassLoader()
sequences will no longer execute. This is another typical example where Java 11 is backwards compatible in the strict sense (because that it’s a URLCassLoader was never specified) but which can nonetheless cause migration challenges.
Symptoms
This one is very obvious. You’ll get a ClassCastException complaining that the new AppClassLoader is no URLClassLoader:
Exception in thread "main" java.lang.ClassCastException:
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader
cannot be cast to java.base/java.net.URLClassLoader
at monitor.Main.logClassPathContent(Main.java:46)
at monitor.Main.main(Main.java:28)
Fixes
The class loader was probably cast to access methods specific to URLClassLoader. If so, you might have to face some serious changes.
...
If you’ve used theURLClassLoader
to dynamically load user provided code (for example as part of a plugin infrastructure) by appending to the class path, then you have to find a new way to do that as it can not be done with Java 11. You should instead consider creating a new class loader for that. This has the added advantage that you’ll be able to get rid of the new classes as they are not loaded into the application class loader. You should also read up on layers – they give you a clean abstraction for loading an entirely new module graph.
> "So, correct me if I'm wrong, but it seems like the method is being invoked but is throwing a javafx.fxml.LoadException which gets wrapped by the other two exceptions. My guess is that the new URLClassLoader you create is missing some FXML files that it's trying to load. What is the full stack trace of your LoadException?" - Correct
– Liz3
Nov 20 at 19:11
Did you find which resources it was trying to load, and make sure they are included in your Classloader?
– xtratic
Nov 20 at 19:12
No, since i don´t exactly know how to load them, i am assuming:val child = URLClassLoader( arrayOf(URL(ideFile.toURI().toURL().toString())), Installer::class.java.classLoader)
is loading all classes and resources.
– Liz3
Nov 20 at 19:17
> "You should instead consider creating a new class loader for that." Seams like the best solution
– Liz3
Nov 20 at 19:27
I think you've already covered that part with creating theURLClassLoader
, I think now you just need to set that classloader on yourFXMLLoader
.
– xtratic
Nov 20 at 19:29
|
show 2 more comments
When you are using the new URLClassLoader
it seems like the method is being invoked but is throwing a javafx.fxml.LoadException
which gets wrapped by the PrivilegedActionException
and InvocationTargetException
.
Even though you load your class with your own URLClassloader
it looks like the FXML parser is trying to load the FX beans with the built-in classloader, which doesn't know about those classes in the FXML.
You'll need to make FXMLLoader use the right classloader that contains all the classes referenced by the fxml. Read the source of FXMLLoader
to get an idea of how it handles classloading. You may need to modify the library doing the fxml loading if possible. Look into FXMLLoader.setClassLoader(urlClassLoader)
or possibly setting a SecurityManager
so that the FXMLLoader
will use the calling classloader.
FXMLLoader.java
/**
* Returns the classloader used by this serializer.
* @since JavaFX 2.1
*/
@CallerSensitive
public ClassLoader getClassLoader() {
if (classLoader == null) {
final SecurityManager sm = System.getSecurityManager();
final Class caller = (sm != null) ?
Reflection.getCallerClass() :
null;
return getDefaultClassLoader(caller);
}
return classLoader;
}
private static ClassLoader getDefaultClassLoader(Class caller) {
if (defaultClassLoader == null) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
final ClassLoader callerClassLoader = (caller != null) ?
caller.getClassLoader() :
null;
if (needsClassLoaderPermissionCheck(callerClassLoader, FXMLLoader.class.getClassLoader())) {
sm.checkPermission(GET_CLASSLOADER_PERMISSION);
}
}
return Thread.currentThread().getContextClassLoader();
}
return defaultClassLoader;
}
I had a guess that Java11 may have changed it's classloader.
See this link (contents pasted below)
Casting To URL Class Loader
Java 9 and the module system improved the platform’s class loading strategy, which is implemented in a new type and in Java 11 the application class loader is of that type. That means it is not aURLClassLoader
, anymore, so the occasional(URLClassLoader) getClass().getClassLoader()
or(URLClassLoader) ClassLoader.getSystemClassLoader()
sequences will no longer execute. This is another typical example where Java 11 is backwards compatible in the strict sense (because that it’s a URLCassLoader was never specified) but which can nonetheless cause migration challenges.
Symptoms
This one is very obvious. You’ll get a ClassCastException complaining that the new AppClassLoader is no URLClassLoader:
Exception in thread "main" java.lang.ClassCastException:
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader
cannot be cast to java.base/java.net.URLClassLoader
at monitor.Main.logClassPathContent(Main.java:46)
at monitor.Main.main(Main.java:28)
Fixes
The class loader was probably cast to access methods specific to URLClassLoader. If so, you might have to face some serious changes.
...
If you’ve used theURLClassLoader
to dynamically load user provided code (for example as part of a plugin infrastructure) by appending to the class path, then you have to find a new way to do that as it can not be done with Java 11. You should instead consider creating a new class loader for that. This has the added advantage that you’ll be able to get rid of the new classes as they are not loaded into the application class loader. You should also read up on layers – they give you a clean abstraction for loading an entirely new module graph.
> "So, correct me if I'm wrong, but it seems like the method is being invoked but is throwing a javafx.fxml.LoadException which gets wrapped by the other two exceptions. My guess is that the new URLClassLoader you create is missing some FXML files that it's trying to load. What is the full stack trace of your LoadException?" - Correct
– Liz3
Nov 20 at 19:11
Did you find which resources it was trying to load, and make sure they are included in your Classloader?
– xtratic
Nov 20 at 19:12
No, since i don´t exactly know how to load them, i am assuming:val child = URLClassLoader( arrayOf(URL(ideFile.toURI().toURL().toString())), Installer::class.java.classLoader)
is loading all classes and resources.
– Liz3
Nov 20 at 19:17
> "You should instead consider creating a new class loader for that." Seams like the best solution
– Liz3
Nov 20 at 19:27
I think you've already covered that part with creating theURLClassLoader
, I think now you just need to set that classloader on yourFXMLLoader
.
– xtratic
Nov 20 at 19:29
|
show 2 more comments
When you are using the new URLClassLoader
it seems like the method is being invoked but is throwing a javafx.fxml.LoadException
which gets wrapped by the PrivilegedActionException
and InvocationTargetException
.
Even though you load your class with your own URLClassloader
it looks like the FXML parser is trying to load the FX beans with the built-in classloader, which doesn't know about those classes in the FXML.
You'll need to make FXMLLoader use the right classloader that contains all the classes referenced by the fxml. Read the source of FXMLLoader
to get an idea of how it handles classloading. You may need to modify the library doing the fxml loading if possible. Look into FXMLLoader.setClassLoader(urlClassLoader)
or possibly setting a SecurityManager
so that the FXMLLoader
will use the calling classloader.
FXMLLoader.java
/**
* Returns the classloader used by this serializer.
* @since JavaFX 2.1
*/
@CallerSensitive
public ClassLoader getClassLoader() {
if (classLoader == null) {
final SecurityManager sm = System.getSecurityManager();
final Class caller = (sm != null) ?
Reflection.getCallerClass() :
null;
return getDefaultClassLoader(caller);
}
return classLoader;
}
private static ClassLoader getDefaultClassLoader(Class caller) {
if (defaultClassLoader == null) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
final ClassLoader callerClassLoader = (caller != null) ?
caller.getClassLoader() :
null;
if (needsClassLoaderPermissionCheck(callerClassLoader, FXMLLoader.class.getClassLoader())) {
sm.checkPermission(GET_CLASSLOADER_PERMISSION);
}
}
return Thread.currentThread().getContextClassLoader();
}
return defaultClassLoader;
}
I had a guess that Java11 may have changed it's classloader.
See this link (contents pasted below)
Casting To URL Class Loader
Java 9 and the module system improved the platform’s class loading strategy, which is implemented in a new type and in Java 11 the application class loader is of that type. That means it is not aURLClassLoader
, anymore, so the occasional(URLClassLoader) getClass().getClassLoader()
or(URLClassLoader) ClassLoader.getSystemClassLoader()
sequences will no longer execute. This is another typical example where Java 11 is backwards compatible in the strict sense (because that it’s a URLCassLoader was never specified) but which can nonetheless cause migration challenges.
Symptoms
This one is very obvious. You’ll get a ClassCastException complaining that the new AppClassLoader is no URLClassLoader:
Exception in thread "main" java.lang.ClassCastException:
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader
cannot be cast to java.base/java.net.URLClassLoader
at monitor.Main.logClassPathContent(Main.java:46)
at monitor.Main.main(Main.java:28)
Fixes
The class loader was probably cast to access methods specific to URLClassLoader. If so, you might have to face some serious changes.
...
If you’ve used theURLClassLoader
to dynamically load user provided code (for example as part of a plugin infrastructure) by appending to the class path, then you have to find a new way to do that as it can not be done with Java 11. You should instead consider creating a new class loader for that. This has the added advantage that you’ll be able to get rid of the new classes as they are not loaded into the application class loader. You should also read up on layers – they give you a clean abstraction for loading an entirely new module graph.
When you are using the new URLClassLoader
it seems like the method is being invoked but is throwing a javafx.fxml.LoadException
which gets wrapped by the PrivilegedActionException
and InvocationTargetException
.
Even though you load your class with your own URLClassloader
it looks like the FXML parser is trying to load the FX beans with the built-in classloader, which doesn't know about those classes in the FXML.
You'll need to make FXMLLoader use the right classloader that contains all the classes referenced by the fxml. Read the source of FXMLLoader
to get an idea of how it handles classloading. You may need to modify the library doing the fxml loading if possible. Look into FXMLLoader.setClassLoader(urlClassLoader)
or possibly setting a SecurityManager
so that the FXMLLoader
will use the calling classloader.
FXMLLoader.java
/**
* Returns the classloader used by this serializer.
* @since JavaFX 2.1
*/
@CallerSensitive
public ClassLoader getClassLoader() {
if (classLoader == null) {
final SecurityManager sm = System.getSecurityManager();
final Class caller = (sm != null) ?
Reflection.getCallerClass() :
null;
return getDefaultClassLoader(caller);
}
return classLoader;
}
private static ClassLoader getDefaultClassLoader(Class caller) {
if (defaultClassLoader == null) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
final ClassLoader callerClassLoader = (caller != null) ?
caller.getClassLoader() :
null;
if (needsClassLoaderPermissionCheck(callerClassLoader, FXMLLoader.class.getClassLoader())) {
sm.checkPermission(GET_CLASSLOADER_PERMISSION);
}
}
return Thread.currentThread().getContextClassLoader();
}
return defaultClassLoader;
}
I had a guess that Java11 may have changed it's classloader.
See this link (contents pasted below)
Casting To URL Class Loader
Java 9 and the module system improved the platform’s class loading strategy, which is implemented in a new type and in Java 11 the application class loader is of that type. That means it is not aURLClassLoader
, anymore, so the occasional(URLClassLoader) getClass().getClassLoader()
or(URLClassLoader) ClassLoader.getSystemClassLoader()
sequences will no longer execute. This is another typical example where Java 11 is backwards compatible in the strict sense (because that it’s a URLCassLoader was never specified) but which can nonetheless cause migration challenges.
Symptoms
This one is very obvious. You’ll get a ClassCastException complaining that the new AppClassLoader is no URLClassLoader:
Exception in thread "main" java.lang.ClassCastException:
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader
cannot be cast to java.base/java.net.URLClassLoader
at monitor.Main.logClassPathContent(Main.java:46)
at monitor.Main.main(Main.java:28)
Fixes
The class loader was probably cast to access methods specific to URLClassLoader. If so, you might have to face some serious changes.
...
If you’ve used theURLClassLoader
to dynamically load user provided code (for example as part of a plugin infrastructure) by appending to the class path, then you have to find a new way to do that as it can not be done with Java 11. You should instead consider creating a new class loader for that. This has the added advantage that you’ll be able to get rid of the new classes as they are not loaded into the application class loader. You should also read up on layers – they give you a clean abstraction for loading an entirely new module graph.
edited Nov 20 at 19:54
answered Nov 20 at 18:22
xtratic
2,3911822
2,3911822
> "So, correct me if I'm wrong, but it seems like the method is being invoked but is throwing a javafx.fxml.LoadException which gets wrapped by the other two exceptions. My guess is that the new URLClassLoader you create is missing some FXML files that it's trying to load. What is the full stack trace of your LoadException?" - Correct
– Liz3
Nov 20 at 19:11
Did you find which resources it was trying to load, and make sure they are included in your Classloader?
– xtratic
Nov 20 at 19:12
No, since i don´t exactly know how to load them, i am assuming:val child = URLClassLoader( arrayOf(URL(ideFile.toURI().toURL().toString())), Installer::class.java.classLoader)
is loading all classes and resources.
– Liz3
Nov 20 at 19:17
> "You should instead consider creating a new class loader for that." Seams like the best solution
– Liz3
Nov 20 at 19:27
I think you've already covered that part with creating theURLClassLoader
, I think now you just need to set that classloader on yourFXMLLoader
.
– xtratic
Nov 20 at 19:29
|
show 2 more comments
> "So, correct me if I'm wrong, but it seems like the method is being invoked but is throwing a javafx.fxml.LoadException which gets wrapped by the other two exceptions. My guess is that the new URLClassLoader you create is missing some FXML files that it's trying to load. What is the full stack trace of your LoadException?" - Correct
– Liz3
Nov 20 at 19:11
Did you find which resources it was trying to load, and make sure they are included in your Classloader?
– xtratic
Nov 20 at 19:12
No, since i don´t exactly know how to load them, i am assuming:val child = URLClassLoader( arrayOf(URL(ideFile.toURI().toURL().toString())), Installer::class.java.classLoader)
is loading all classes and resources.
– Liz3
Nov 20 at 19:17
> "You should instead consider creating a new class loader for that." Seams like the best solution
– Liz3
Nov 20 at 19:27
I think you've already covered that part with creating theURLClassLoader
, I think now you just need to set that classloader on yourFXMLLoader
.
– xtratic
Nov 20 at 19:29
> "So, correct me if I'm wrong, but it seems like the method is being invoked but is throwing a javafx.fxml.LoadException which gets wrapped by the other two exceptions. My guess is that the new URLClassLoader you create is missing some FXML files that it's trying to load. What is the full stack trace of your LoadException?" - Correct
– Liz3
Nov 20 at 19:11
> "So, correct me if I'm wrong, but it seems like the method is being invoked but is throwing a javafx.fxml.LoadException which gets wrapped by the other two exceptions. My guess is that the new URLClassLoader you create is missing some FXML files that it's trying to load. What is the full stack trace of your LoadException?" - Correct
– Liz3
Nov 20 at 19:11
Did you find which resources it was trying to load, and make sure they are included in your Classloader?
– xtratic
Nov 20 at 19:12
Did you find which resources it was trying to load, and make sure they are included in your Classloader?
– xtratic
Nov 20 at 19:12
No, since i don´t exactly know how to load them, i am assuming:
val child = URLClassLoader( arrayOf(URL(ideFile.toURI().toURL().toString())), Installer::class.java.classLoader)
is loading all classes and resources.– Liz3
Nov 20 at 19:17
No, since i don´t exactly know how to load them, i am assuming:
val child = URLClassLoader( arrayOf(URL(ideFile.toURI().toURL().toString())), Installer::class.java.classLoader)
is loading all classes and resources.– Liz3
Nov 20 at 19:17
> "You should instead consider creating a new class loader for that." Seams like the best solution
– Liz3
Nov 20 at 19:27
> "You should instead consider creating a new class loader for that." Seams like the best solution
– Liz3
Nov 20 at 19:27
I think you've already covered that part with creating the
URLClassLoader
, I think now you just need to set that classloader on your FXMLLoader
.– xtratic
Nov 20 at 19:29
I think you've already covered that part with creating the
URLClassLoader
, I think now you just need to set that classloader on your FXMLLoader
.– xtratic
Nov 20 at 19:29
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398392%2fjdk-11-run-a-jar-archive-through-reflection-which-depends-on-libraries%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is that the full stack trace of your
LoadException
?– xtratic
Nov 20 at 19:09
no, here the full stacktrace: hastebin.com/lesorudewa.cs
– Liz3
Nov 20 at 19:14
Ohhhh... FXML is using the built in classloader to load the FX beans, which of course doesn't know about those classes.
– xtratic
Nov 20 at 19:17
You'll probably need to call
FXMLLoader.setClassLoader(urlClassLoader)
– xtratic
Nov 20 at 19:27