Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

javafx.graphics does not export com.sun.javafx.scene.layout to unnamed module #6

Closed
degloff opened this issue Jul 17, 2019 · 5 comments

Comments

@degloff
Copy link

degloff commented Jul 17, 2019

I get a runtime exception when running any example.

I use java11 and this commit:

8f5afda

Here is the exception:

/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:56233,suspend=y,server=n -

......

slf4j-api/1.7.25/slf4j-api-1.7.25.jar:/Users/dani/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/191.7479.19/IntelliJ IDEA.app/Contents/lib/idea_rt.jar" -p /Users/dani/.m2/repository/org/openjfx/javafx-base/11/javafx-base-11-mac.jar:/Users/dani/.m2/repository/org/openjfx/javafx-graphics/12.0.1/javafx-graphics-12.0.1-mac.jar de.gsi.chart.samples.RunChartSamples
Connected to the target VM, address: '127.0.0.1:56233', transport: 'socket'
Exception in Application constructor
java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class de.gsi.chart.samples.RunChartSamples
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:890)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:802)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
	at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run$$$capture(InvokeLaterDispatcher.java:96)
	at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java)
Caused by: java.lang.IllegalAccessError: superclass access check failed: class com.sun.javafx.scene.control.ControlHelper (in unnamed module @0x17776a8) cannot access class com.sun.javafx.scene.layout.RegionHelper (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.scene.layout to unnamed module @0x17776a8
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:802)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:700)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:623)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	at javafx.scene.control.Control.<clinit>(Control.java:86)
	at de.gsi.chart.samples.RunChartSamples.<init>(RunChartSamples.java:55)
	... 11 more
Exception running application de.gsi.chart.samples.RunChartSamples
@wirew0rm
Copy link
Member

Hey, this is due to javafx using the jigsaw java module system and chart-fx not using it. There are multiple ways to resolve this:

  1. run with maven:
    bash mvn exec:java -Dproject.mainClass=de.gsi.chart.samples.<sample>
    This should allways work, but not very practical for use in IDEs (e.g. no incremental compilation). Maven does some magic to automatically set the right jvm parameters.
  2. use de.gsi.samples.utils.JavaFXLauncher (good for testing from inside IDEs, look into its javadoc for how it is supposed to work)
  3. add the appropriate --add-module and --opens jvm arguments. I'm currently not at my development machine, but i can look them up tomorrow morning.

This was one of the major hurdles in adding support for openjdk11/openjfx, obvously documentation for this should be improved.
The ultimate Problem is of course, that these parameters are even necessary. We also tried to implement jigsaw, but as some of our dependencies do not use jigsaw (they don't even provide a module name in the Manifest), this created a whole lot of other problems (also in combination with maven), so we decided to not use jigsaw for now.

@wirew0rm
Copy link
Member

I just looked up the required JVM arguments, in eclipse they have to be added to run configuration->VM arguments, other IDEs should have similar settings:
--add-modules=javafx.swing,javafx.graphics,javafx.fxml,javafx.media,javafx.web --add-reads javafx.graphics=ALL-UNNAMED --add-opens javafx.controls/com.sun.javafx.charts=ALL-UNNAMED --add-opens javafx.graphics/com.sun.javafx.iio=ALL-UNNAMED --add-opens javafx.graphics/com.sun.javafx.iio.common=ALL-UNNAMED --add-opens javafx.graphics/com.sun.javafx.css=ALL-UNNAMED --add-opens javafx.base/com.sun.javafx.runtime=ALL-UNNAMED

@wirew0rm
Copy link
Member

I have added this information to the README.md, and will close this issue, feel free to reopen or create a new issue if you have more questions/problems.

@Niekaiyuan
Copy link

Hi,I hava a question:I already added JVM arguments but when I running my code,it's show Module javafx.swing not found.And I have been used Maven to add the dependent of javafx-swing

@wirew0rm
Copy link
Member

Hey @Niekaiyuan,

since last year, we have been able to eliminate chart-fx's dependency on the javafx-swing module. So you should just remove the chartfx-swing entry from the add-modules list assuming your project doesn't otherwise use this module. I will update the README.md accordingly, thanks for bringing this up and please report back if this was indeed the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants