Java 9:将包导出到未命名的模块失败 [英] Java 9: Exporting packages to unnamed modules fail

查看:236
本文介绍了Java 9:将包导出到未命名的模块失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试针对Java 9构建开源项目.有些文件我需要使用反射来访问,但是不能,因为软件包不是由其模块导出的.我使用参数--add-exports将软件包导出到未命名的模块.

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.

我在环境变量_JAVA_OPTIONS中添加了以下参数:

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

我正在使用最新的JDK 9构建(截至今天):

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.

推荐答案

您添加的标志(似乎是正确的标志)似乎没有添加到编译器,而是运行Gradle的进程.指示您有关--illegal-access的消息的指示,该消息仅在java上可用,而在javac上不可用.

It looks like the flags you add (which seem to be the right ones) are not added to the compiler but the process that runs Gradle. An indication of that are the messages that inform you about --illegal-access, which is only available on java, not javac.

使用Java 9时,有时很难将参数传递到正确的位置.对于Gradle 这可能会有帮助.

When working with Java 9 it can sometimes be tough to get the arguments to the right places. For Gradle this might help.

这篇关于Java 9:将包导出到未命名的模块失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆