miho / MonacoFX

JavaFX editor node based on the powerful Monaco editor that drives VS Code
MIT License
75 stars 25 forks source link

superclass access check failure when creating new instance of MonacoFX #19

Closed EasyG0ing1 closed 1 year ago

EasyG0ing1 commented 2 years ago

Hello,

Using Java 16, if I simply create a new JavaFX application in IntelliJ, then add the Maven dependency for MonacoFX, then add this to the module-info.java file:

requires eu.mihosoft.monacofx;

Then add this one line to the starting class (which does run successfully without adding this line):

MonacoFX monacoFX = new MonacoFX();

I receive this error when I try to run the code:

java.lang.reflect.InvocationTargetException
...
Caused by: java.lang.RuntimeException: Exception in Application start method
...
Caused by: java.lang.IllegalAccessError: superclass access check failed: class com.sun.javafx.sg.prism.web.NGWebView (in unnamed module @0x1da23d11) cannot access class com.sun.javafx.sg.prism.NGGroup (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.sg.prism to unnamed module @0x1da23d11

Any ideas on how to fix it?

Thank you,

Mike

EasyG0ing1 commented 2 years ago

After creating a question about this problem on stackoverflow.com, which can be seen here, I made the following adjustments to my project, which ended up fixing this issue, and now my project runs and MonacoFX works beautifully:

First, I had to add this to my module-info.java file:

requires javafx.web;
requires eu.mihosoft.monacofx;

Next, I changed my JDK in IntelliJ to use version 17.0.1 and I made these changes in my POM file:

    <properties>
        <java.version>17</java.version>
        <javafx.version>17.0.1</javafx.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>net.synedra</groupId>
            <artifactId>validatorfx</artifactId>
            <version>0.1.13</version>
            <exclusions>
                <exclusion>
                    <groupId>org.openjfx</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-web</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>eu.mihosoft.monacofx</groupId>
            <artifactId>monacofx</artifactId>
            <version>0.0.7</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.7</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.2.0</version>
            </plugin>
        </plugins>
    </build>
</project>
miho commented 1 year ago

This is related to Java modules. MonacoFX supports automatic-module names but does not include a module-ionfo.java. Therefore, if you choose to use the module system you are required to declare the dependencies.