4

It's been 3 days that I look on the internet how to fix this on gradle

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

On simple idea projects I was adding

--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.base/com.sun.javafx.event=com.jfoenix 

I know, I have to add jvm options but how do I ?

I'm using gradle javafx 11.0.2, java 11, on intellij idea,

this is the build.gradle

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
}

compileJava.options.encoding = 'UTF-8'
repositories {
    mavenCentral()
}

dependencies {
    //     https://mvnrepository.com/artifact/com.jfoenix/jfoenix
    compile group: 'com.jfoenix', name: 'jfoenix', version: '9.0.9'
    compile group: 'de.jensd', name: 'fontawesomefx-fontawesome', version: '4.7.0-9.1.2'
    // https://mvnrepository.com/artifact/de.jensd/fontawesomefx-commons
    runtime group: 'de.jensd', name: 'fontawesomefx-commons', version: '9.1.2'
// https://mvnrepository.com/artifact/com.h2database/h2
    compile group: 'com.h2database', name: 'h2', version: '1.4.199'
}

javafx {
    version = "11.0.2"
    modules = [ 'javafx.controls', 'javafx.fxml','javafx.graphics','javafx.base' ]
}

mainClassName = 'org.yanisboukir.agence.Main'

Thanks

fabian
  • 80,457
  • 12
  • 86
  • 114
Yanis Boukir
  • 45
  • 1
  • 5

4 Answers4

6

If you are running a non modular project (you don't have module-info.java), to include the VM arguments in your run task, all you need to add to your build.gradle file is:

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

Note that in this case, you can't use --add-exports=...=com.jfoenix.

If you run a modular project, with a module descriptor like:

module hellofx {
    
    requires javafx.controls;
    
    requires javafx.fxml;
    
    requires com.jfoenix;

    
    opens org.openjfx to javafx.fxml;
    
    exports org.openjfx;

}

now these are the VM arguments that you will have to include in your build file:

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"
    ]

}
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • For completeness (or complete confusion) one might add that there are also automatic modules which are somewhere inbetween. You get them if you put a non-modular jar on the module path. The module path is then either derived from the jar file name or from the one specified in the manifest. In this case you cannot use ALL-UNNAMED but you have to use the derived/specified module name although you project may not contain any module-info.java file. – mipa Sep 27 '19 at 13:13
  • Oh run perfectly !!! Thank you very much ! But can i deploy with this ? My project is the same : https://github.com/fthdgn/java11-javafx-demo but just edited main and controllers – Yanis Boukir Sep 27 '19 at 14:53
  • "deploy" as in jlink/jpackage, yes, you have to include these jvmArgs too. See for instance [this](https://github.com/beryx/badass-jlink-plugin#badass-jlink-plugin). On the other hand, if you do a fat jar, everything goes to class path, so you won't need them. – José Pereda Sep 27 '19 at 15:01
  • I Stil got this erros >startup failed: build file 'C:\Users\yanis\PROJECT\java11-javafx-demo-master\app\build.gradle': 54: expecting '}', found 'jvmArgs' @ line 54, column 6. 
 jvmArgs = [
 ^ 1 error – Yanis Boukir Sep 27 '19 at 15:19
  • Don't you have to add it to your `app` project's build file? Didn't you say it "runs perfectly"? – José Pereda Sep 27 '19 at 16:06
  • I think I added it in another window or project Please can I this vmp options directly in java compiler ? I'm so sorry i'm gradle noob >compileJava { options.fork = true options.compilerArgs.addAll(['--add-exports', 'javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix']) } I tried that but no changes – Yanis Boukir Sep 27 '19 at 16:10
  • It is impossible for me to follow up on your changes over comments... If your initial question has been answered, consider accepting this answer as a valid solution. Then spend some time trying to apply it to your other project. If you still have issues, then post a new question with them. – José Pereda Sep 27 '19 at 16:16
  • I tried run { jvmArgs +=['--add-exports','javafx.controls/com.sun.javafx.scene.controlr=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 think that the probleme was in syntax,But not work in deloy :( – Yanis Boukir Sep 27 '19 at 16:23
  • As I said, open a new question with your `build.gradle`, what you are trying to achieve and the errors you are facing. – José Pereda Sep 27 '19 at 16:25
  • You appear to have `--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=[ALL-UNNAMED|com.jfoenix]` twice, both at the start and the end of the list. Am I missing something or is that just a mistake? – Slaw Sep 28 '19 at 05:44
  • I'd initially tried exporting the sun packages as though the project were modular, that is: --add-exports=javafx.controls/comALL-UNNAMED|.sun.javafx.scene.control.behavior=com.jfoenixand received the warning that 'com.jfoenix' wasn't found. Replacing this name with 'ALL-UNNAMED' resolved the issue! – Adrian M. Mar 15 '20 at 02:18
2

For newer versions of Gradle (6.x) the following worked for me:

compileJava {
    options.compilerArgs.add('--add-exports=java.base/jdk.internal.vm.annotation=ALL-UNNAMED')
}

For Java test code:

compileTestJava {
    options.compilerArgs.add('--add-exports=java.base/jdk.internal.vm.annotation=ALL-UNNAMED')
}
sakra
  • 62,199
  • 16
  • 168
  • 151
0
  • Compile-time following:
compileJava {
    options.compilerArgs.add('--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix')
    options.compilerArgs.add('--add-exports=javafx.controls/com.sun.javafx.scene.control=com.jfoenix')
    options.compilerArgs.add('--add-exports=--add-exports=javafx.base/com.sun.javafx.binding=com.jfoenix')
    options.compilerArgs.add('--add-exports=javafx.graphics/com.sun.javafx.stage=com.jfoenix')
}
  • Run-time following
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"
    ]

}

We must set both of them. If we only set the first one idea can compile, however at the run time throw exception. Thanks @sakra @José Pereda

Satsrag
  • 33
  • 7
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",
    ]
}
Youssef Idraiss
  • 396
  • 5
  • 19