--release 不允许从系统模块导出包 [英] Exporting a package from system module is not allowed with --release

查看:82
本文介绍了--release 不允许从系统模块导出包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下程序:

module-info.java

module a {}

Main.java

public class Main {公共静态无效主(字符串 [] args){System.out.println(sun.nio.ByteBuffered.class);}}

这个程序使用--add-exports选项成功编译:

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

但是,当我添加 --release 参数时,它失败了:

>javac --add-exports java.base/sun.nio=a --release 9 module-info.java Main.java错误:不允许使用 --release 从系统模块 java.base 导出包1 错误

基本上,这两个命令是等价的.那么为什么禁止后者呢?

此外,由于 IDEA 将 --release 参数传递给 javac,如果我的项目需要内部 API,这使得在 IDEA 中进行开发变得不可能.

我使用的是 JDK 9+178.

解决方案

它出现在 this--release 不能与 --add-exports--add-reads--patch-module.

来自链接:

<块引用>

这里的总体建议是让 make --release 9 始终如一地工作在 JDK 9 和(预期的)JDK 10 之间,即使以命令的可能不同行为,例如:
$ /javac Test.java
$ /javac --release 9 Test.java

还有:

<块引用>

考虑到 --release 的意图,这应该是可以接受的 - 允许使用给定 JDK 版本支持的 API 编译代码.

特别是建议:

-防止将--add-exports、-add-reads 和--patch-module 与--release(任何版本)结合用于系统模块

这里是包含以下内容的文件差异:><块引用>

不允许从系统模块 {0} 导出包--发布

我无法评论其基本原理,但从上面的引用来看,它涉及允许 JDK 9 与 JDK 10 一致地工作.

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:
$ <jdk9>/javac Test.java
$ <jdk9>/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.

这篇关于--release 不允许从系统模块导出包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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