1

i was trying to create compile my application and create an executable file. as for now i see the best tool to use is javafx-maven-plugin.

i couldn't get it to work, so i started with a basic code that is generated when creating a project according to this.

https://www.youtube.com/watch?v=4vd-RE0X5Lg

https://openjfx.io/openjfx-docs/#maven

the basic example works but when i tried the same structure in my code or by simply adding a code that contains jfoenix to it. it cannot run.

following line seems to be the important line of the error,

Caused by: java.lang.IllegalAccessError: class com.jfoenix.skins.JFXSpinnerSkin (in module com.jfoenix) cannot access class com.sun.javafx.scene.NodeHelper (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.scene to module com.jfoenix

how can i fix this?

this is pom i has sofar.

<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>org.openjfx</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <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-controls</artifactId>
            <version>14</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>14</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>14</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>14</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-base</artifactId>
            <version>14</version>
        </dependency>
        <dependency>
            <groupId>com.jfoenix</groupId>
            <artifactId>jfoenix</artifactId>
            <version>9.0.9</version>
        </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>
                    <compilerArgs>
                        <arg>--add-opens</arg><arg>javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.3</version>
                <configuration>
                    <mainClass>org.openjfx.App</mainClass>
                    <options>
                        <option>--add-opens</option>
                        <option>javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED</option>
                    </options>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Eshaka
  • 974
  • 1
  • 14
  • 38

1 Answers1

2

Based on the code you shared : https://github.com/Ealuthwala/javafx-export

I edited and the POM so that it runs, and this is the output I see enter image description here

I am sharing the POM below, just use this POM and it should work.

Apart from this you must use JDK 11.0.2 or lower. You need to change settings of your IDE to pick up JDK 11.0.2 or lower for this project.

Because you are using features of JFoenix which will not work with a higher version of JDK. Reason is explained here : https://github.com/jfoenixadmin/JFoenix/issues/955

With this you will be able to make this code run on mobile (64-bit android and iPhone ) using GluonVM, and Desktop, Linux, Mac, and web (using JPro), rasberry pie etc. So practically you cannot have any problem with this unless you have a very big reason for wanting to upgrade to Jdk 12. If you give time, may be a year, I am sure JFoenix team will fix it, if it is not done, and you really find JFoenix very useful you can either pitch in and contribute the fixes or use something else.

<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>org.openjfx</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source> <!-- DO NOT USE JDK greater than 11 -->
        <maven.compiler.target>11</maven.compiler.target> <!-- DO NOT USE JDK greater than 11 -->
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>com.jfoenix</groupId>
            <artifactId>jfoenix</artifactId>
            <version>9.0.9</version>
        </dependency>
        <dependency>
            <groupId>io.datafx</groupId>
            <artifactId>datafx</artifactId>
            <version>8.0.7</version>
        </dependency>
        <dependency>
            <groupId>io.datafx</groupId>
            <artifactId>flow</artifactId>
            <version>8.0.7</version>
        </dependency>
        <dependency>
            <groupId>org.kordamp.ikonli</groupId>
            <artifactId>ikonli-javafx</artifactId>
            <version>11.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.kordamp.ikonli</groupId>
            <artifactId>ikonli-fontawesome5-pack</artifactId>
            <version>11.4.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <!--
        This is what will make the code actually run.
                This is taken from José Pereda's answer from
                https://stackoverflow.com/a/56467911/2448015
            -->
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.4</version>
                <configuration>
                    <mainClass>org.openjfx.App</mainClass>
                    <options>
                        <option>--add-opens</option><option>javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED</option>
                        <option>--add-opens</option><option>javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED</option>
                        <option>--add-opens</option><option>javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED</option>
                        <option>--add-opens</option><option>javafx.base/com.sun.javafx.binding=ALL-UNNAMED</option>
                        <option>--add-opens</option><option>javafx.graphics/com.sun.javafx.stage=ALL-UNNAMED</option>
                        <option>--add-opens</option><option>javafx.base/com.sun.javafx.event=ALL-UNNAMED</option>
                        <option>--add-exports</option><option>javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED</option>
                        <option>--add-exports</option><option>javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED</option>
                        <option>--add-exports</option><option>javafx.base/com.sun.javafx.binding=ALL-UNNAMED</option>
                        <option>--add-exports</option><option>javafx.graphics/com.sun.javafx.stage=ALL-UNNAMED</option>
                        <option>--add-exports</option><option>javafx.base/com.sun.javafx.event=ALL-UNNAMED</option>
                        <!--
                            Refer : https://github.com/jfoenixadmin/JFoenix/issues/889#issuecomment-450744122
                            In order to make jfoenix works, it should need less and doesn't need all of these.
                            You may have to go one by one to find what - - add-opens ... you'll need in your case.
                            - - add-opens is for enabling deep-reflection
                            - - add-exports is for direct access
                        -->
                    </options>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
  • thanks for the help. i changed my pom according to this.. but i keep getting the exact same error. – Eshaka Apr 28 '20 at 07:20
  • and 0.0.4 version of the plugin can't run at all.. i was using the 0.0.3 version – Eshaka Apr 28 '20 at 07:21
  • yes, thats how i ran it, nothing has changed, i can upload my project if you can take a look – Eshaka Apr 28 '20 at 14:58
  • @Eshaka yes please give, let me see. Meanwhile download the code I sent and just run it, it will run. Just execute ``mvn javafx:run`` – Sri Nithya Sharabheshwarananda Apr 28 '20 at 15:10
  • yes, I tried that. some of the dependencies were not found, so I changed some versions. then it started to work. nut code isn't working – Eshaka Apr 29 '20 at 00:54
  • @Eshaka see the answer, I edited it. I have put a screenshot. And any further discussion avoid in comments as it is a stack-overflow guideline not to have extended discussions in the comments. Use the chat feature instead. I am 100% sure your problem is solved. – Sri Nithya Sharabheshwarananda Apr 29 '20 at 03:42
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/212763/discussion-between-eshaka-and-sri-nithya-sharabheshwarananda). – Eshaka Apr 29 '20 at 07:38