0

I'm using javafx 11.0.2 and java 11.0.3 In order to discover 'gradle' I downloaded this project https://github.com/fthdgn/java11-javafx-demo and when I add jfoenix controls in main.fxml like this

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.*?>
<?import com.jfoenix.controls.JFXTextField?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXTabPane?>
<?import javafx.scene.control.Tab?>
<AnchorPane xmlns="http://javafx.com/javafx/8.0.121"
            xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.fthdgn.app.controller.MainController">
    <VBox alignment="CENTER" spacing="10.0" AnchorPane.bottomAnchor="10"
          AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10" fx:id="vbox">
        <TextField fx:id="inputTextField"/>
        <Button mnemonicParsing="false" onAction="#reveseButtonClicked" text="Reverse"/>
        <TextField fx:id="outputTextField"/>
        <JFXTextField fx:id="tf"/>
        <JFXButton text="AZUL" fx:id="button"/>
        <JFXTabPane>
            <Tab>
            </Tab>
        </JFXTabPane>

    </VBox>
</AnchorPane>

I got this famous error

Caused by: java.lang.IllegalAccessError: class com.jfoenix.skins.JFXTabPaneSkin (in module com.jfoenix) cannot access class com.sun.javafx.scene.control.behavior.TabPaneBehavior (in module javafx.controls) because module javafx.controls does not export com.sun.javafx.scene.control.behavior to module com.jfoenix

I have edited the build.gradle to add some jvm options( for module app ) like this

plugins {
    id 'java'
    id 'application'
    id 'com.zyxist.chainsaw' version '0.3.1'
    id 'org.beryx.jlink' version '2.15.1'
}
compileJava.options.encoding = 'UTF-8'

import org.gradle.internal.jvm.Jvm
import org.gradle.internal.os.OperatingSystem

group 'com.fthdgn'
version '1.0-SNAPSHOT'

sourceCompatibility = 11
targetCompatibility = 11

repositories {
    mavenCentral()
}

mainClassName = mainClass

def currentOS = OperatingSystem.current()
def platform
if (currentOS.isWindows()) {
    platform = 'win'
} else if (currentOS.isLinux()) {
    platform = 'linux'
} else if (currentOS.isMacOsX()) {
    platform = 'mac'
}

jlink {
    javaHome.set(Jvm.current().getJavaHome().getAbsolutePath())

}

dependencies {
    implementation "org.openjfx:javafx-base:11:${platform}"
    implementation "org.openjfx:javafx-graphics:11:${platform}"
    implementation "org.openjfx:javafx-controls:11:${platform}"
    implementation "org.openjfx:javafx-fxml:11:${platform}"
    compile group: 'com.jfoenix', name: 'jfoenix', version: '9.0.9'


}

run {
    jvmArgs += ['--add-exports', 'javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix']
    jvmArgs += ['--add-exports', 'javafx.controls/com.sun.javafx.scene.control=com.jfoenix']
    jvmArgs += ['--add-exports', 'javafx.base/com.sun.javafx.binding=com.jfoenix']
    jvmArgs += ['--add-exports', 'javafx.graphics/com.sun.javafx.stage=com.jfoenix']
    jvmArgs += ['--add-exports', 'javafx.base/com.sun.javafx.event=com.jfoenix']

}


I just added

run {
    jvmArgs += ['--add-exports', 'javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix']
    jvmArgs += ['--add-exports', 'javafx.controls/com.sun.javafx.scene.control=com.jfoenix']
    jvmArgs += ['--add-exports', 'javafx.base/com.sun.javafx.binding=com.jfoenix']
    jvmArgs += ['--add-exports', 'javafx.graphics/com.sun.javafx.stage=com.jfoenix']
    jvmArgs += ['--add-exports', 'javafx.base/com.sun.javafx.event=com.jfoenix']

}


And run like a charm but this is do anything for deploying , how do I do to set this jvmArgs for all task to use jfoenix in gradle with javafx 11 and java 11 ?

module com.fthdgn.app {
    requires javafx.controls;
    requires javafx.fxml;
    requires transitive com.jfoenix;
    opens com.fthdgn.app to javafx.graphics;
    opens com.fthdgn.app.controller to javafx.fxml;
}
Yanis Boukir
  • 45
  • 1
  • 5
  • 1
    Did you consider using the `module-info.java` file in the project for the proper modules support without the JVM options hacks? https://stackoverflow.com/a/57897944/104891 – CrazyCoder Sep 27 '19 at 21:47
  • This is my module-info.java module com.fthdgn.app { requires javafx.controls; requires javafx.fxml; requires transitive com.jfoenix; opens com.fthdgn.app to javafx.graphics; opens com.fthdgn.app.controller to javafx.fxml; } – Yanis Boukir Sep 27 '19 at 21:59

2 Answers2

2

You can follow the documentation for JavaFX 11+, section Modular with Gradle.

There is a sample that makes use of the JavaFX gradle plugin, to deal with the JavaFX dependencies and the build and run tasks, and the Jlink plugin, to deal with deployment of a custom image runtime.

All you have to do is add the Jfoenix dependency to that project, modify its source code accordingly, and finally include the required jvmArgs in both run and jlink tasks, like this:

plugins {
  id 'application'
  id 'org.openjfx.javafxplugin' version '0.0.8'
  id 'org.beryx.jlink' version '2.15.1'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation group: 'com.jfoenix', name: 'jfoenix', version: '9.0.9'
}

javafx {
    version = "13"
    modules = [ 'javafx.controls', 'javafx.fxml' ]
}

run {
    jvmArgs = [
            "--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix",
            "--add-exports=javafx.controls/com.sun.javafx.scene.control=com.jfoenix",
            "--add-exports=javafx.base/com.sun.javafx.binding=com.jfoenix",
            "--add-exports=javafx.graphics/com.sun.javafx.stage=com.jfoenix",
            "--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix",
    ]
}

jlink {
    launcher {
        name = 'hellofx'
        jvmArgs = [
                "--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix",
                "--add-exports=javafx.controls/com.sun.javafx.scene.control=com.jfoenix",
                "--add-exports=javafx.base/com.sun.javafx.binding=com.jfoenix",
                "--add-exports=javafx.graphics/com.sun.javafx.stage=com.jfoenix",
                "--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix",
        ]
    }
}

mainClassName = "$moduleName/org.openjfx.MainApp"

Now you can run your project with:

./gradlew run

and create the runtime image with:

./gradlew jlink

Once it has finished building, you can run it from the script:

build/image/bin/hellofx
José Pereda
  • 44,311
  • 7
  • 104
  • 132
0

this didn't work for me in JDK 16:

run {
    jvmArgs = [
            "--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix",
            "--add-exports=javafx.controls/com.sun.javafx.scene.control=com.jfoenix",
            "--add-exports=javafx.base/com.sun.javafx.binding=com.jfoenix",
            "--add-exports=javafx.graphics/com.sun.javafx.stage=com.jfoenix",
            "--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix",
    ]
}   

what worked instead is

run {
    jvmArgs = [
            "--add-opens=java.base/java.lang.reflect=com.jfoenix",
            "--add-opens=java.base/java.lang.reflect=com.jfoenix",
            "--add-opens=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix",
            "--add-opens=javafx.base/com.sun.javafx.binding=com.jfoenix",
            "--add-opens=javafx.graphics/com.sun.javafx.stage=com.jfoenix",
            "--add-opens=javafx.base/com.sun.javafx.event=com.jfoenix",
    ]
}

the same thing with Jlink VM args

Youssef Idraiss
  • 396
  • 5
  • 19