java.base is not on,使用--release不允许从系统模块导出包

I have the following program:

module-info.java

module a {

}

Main.java

public class Main {

public static void main(String[] args) {

System.out.println(sun.nio.ByteBuffered.class);

}

}

This program successfully compiles with the --add-exports option:

> javac --add-exports java.base/sun.nio=a module-info.java Main.java

However, when I add the --release argument, it fails:

> javac --add-exports java.base/sun.nio=a --release 9 module-info.java Main.java

error: exporting a package from system module java.base is not allowed with --release

1 error

Basically, these two commands are equivalent. So why is the latter one forbidden?

Also, since IDEA passes the --release argument to javac, this makes the development in IDEA impossible if my project needs an internal API.

I'm using JDK 9+178.

解决方案

It appears from this bug ticket that --release cannot be used in combination with --add-exports, --add-reads, and --patch-module.

From the link:

The overall proposal here is to get make --release 9 work consistently

between JDK 9 and the (anticipated) JDK 10, even at the cost of a

possible different behavior of commands like:

$ /javac Test.java

$ /javac --release 9 Test.java

Also:

Which should be acceptable, given the intents of --release - allow to

compile code using supported APIs for the given JDK release.

In particular the proposal is to:

[edit]

-prevents use of --add-exports, -add-reads and --patch-module for system modules in combination with --release (any version)

Here is the file diff that contains:

exporting a package from system module {0} is not allowed with

--release

I can't comment on the rationale but from the above quote, it pertains to allowing JDK 9 to work consistently with JDK 10.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值