I am trying to build an open-source project against Java 9. There are some files which I need to access using reflection but I cannot because the packages are not exported by their modules. I export the packages to unnamed modules by using the arguments --add-exports
.
I have added the following arguments to environment variable _JAVA_OPTIONS
:
-Dsun.reflect.debugModuleAccessChecks=true
--add-exports=javafx.graphics/com.sun.javafx.scene.traversal=ALL-UNNAMED
--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED
I am using the latest JDK 9 build (as of today):
C:\controlsfx>java -version
java version "9"
Java(TM) SE Runtime Environment (build 9+175)
Java HotSpot(TM) 64-Bit Server VM (build 9+175, mixed mode)
Here is the output when I try to build the project:
C:\controlsfx>.\gradlew :controlsfx:build
Picked up _JAVA_OPTIONS: -Dsun.reflect.debugModuleAccessChecks=true --add-exports=javafx.graphics/com.sun.javafx.scene.traversal=ALL-UNNAMED --add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
:controlsfx:compileJava
C:\controlsfx\controlsfx\src\main\java\impl\org\controlsfx\behavior\SnapshotViewBehavior.java:60: error: package com.sun.javafx.scene.control.behavior is not visible
import com.sun.javafx.scene.control.behavior.BehaviorBase;
^
(package com.sun.javafx.scene.control.behavior is declared in module javafx.controls, which does not export it to the unnamed module)
C:\controlsfx\src\main\java\impl\org\controlsfx\ReflectionUtils.java:3: error: package com.sun.javafx.scene.traversal is not visible
import com.sun.javafx.scene.traversal.ParentTraversalEngine;
^
(package com.sun.javafx.scene.traversal is declared in module javafx.graphics, which does not export it to the unnamed module)
The compilation still fails, which makes me wonder what am I doing wrong.