I'm working with a new JavaFX project. I have legacy Swing control panels. When I try to do new SwingNode, I get an exception:
Caused by: java.lang.IllegalAccessError: superclass access check
failed: class com.sun.javafx.embed.swing.SwingNodeHelper (in unnamed
module @0x35dc99d5) cannot access class
com.sun.javafx.scene.NodeHelper (in module javafx.graphics) because
module javafx.graphics does not export com.sun.javafx.scene to
unnamed module @0x35dc99d5
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1027)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
at javafx.embed.swing.SwingNode.<clinit>(SwingNode.java:135)
at test.app.MJFXtest.start(MJFXtest.java:11)
This is on JavaFX v21. I tried 19, but still the same.
package test.app;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.embed.swing.SwingNode;
public class MJFXtest extends Application {
@Override
public void start(Stage primaryStage) {
SwingNode sn = new SwingNode();
}
public static void main(String[] args) {
launch(args);
}
}
I expect this not to throw an exception on the new SwingNode(); line, but to create a new SwingNode.
I saw this Q/A about the same problem, but I have javafx-swing included in my pom file. (https://stackoverflow.com/questions/55874607/the-class-swingnode-in-openjfx-causes-problems) This is the javafx section from pom.xml and it looks like all the relevant libraries are there.
Any assistance would be appreciated. Thank you.
Full commmand line:
d:; cd 'd:\Thomas\Dropbox\Projects\morbid'; & 'C:\Program Files\Java\jdk-21\bin\java.exe' '-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:51624' '@C:\Users\Thomas\AppData\Local\Temp\cp_a1x3p1tfjwls6nptiscdinmdj.argfile' 'com.bobandthomas.morbid.MorbidJFX'```
and full pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bobandthomas.morbid</groupId>
<artifactId>morbid</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>21</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-swing -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>21</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-web -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>21</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx</artifactId>
<version>21</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.vecmath/vecmath -->
<dependency>
<groupId>javax.vecmath</groupId>
<artifactId>vecmath</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>toxi</groupId>
<artifactId>geom</artifactId>
<version>0021</version>
<scope>system</scope>
<systemPath>D:\Thomas\toxiclibs\toxiclibscore.jar</systemPath>
</dependency>
<dependency>
<groupId>toxi</groupId>
<artifactId>volume</artifactId>
<version>0021</version>
<scope>system</scope>
<systemPath>D:\Thomas\toxiclibs\volumeutils.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.bobandthomas.morbid.App</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<argLine> --add-exports javafx.graphics/com.sun.javafx.application=ALL-UNNAMED </argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>