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

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

问题描述

我有以下计划:



module-info.java

 模块a {
}

Main.java

  public class Main {
public static void main(String [] 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 
错误:不允许从系统模块java.base导出包--release
1错误

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



此外,由于IDEA将 - release 参数传递给javac,如果我的项目需要内部API,则无法在IDEA中进行开发。



我正在使用JDK 9 + 178。

解决方案

它出现在此错误票 - 发布不能与 - add-exports - add-reads 和 - patch-module



从链接:


此处的总体建议是获取 - -release 9在JDK 9和(预期)JDK 10之间一致地工作
,即使以
可能的不同命令行为为代价,例如:

$< jdk9> / javac Test.java

$< jdk9> / javac --release 9 Test.java


另外:


哪个应该考虑到--release的意图 - 允许
使用受支持的API为给定的JDK版本编译代码。



特别提案是:



[edit]



-prevents使用--add-exports,-add-reads和--patch-module与系统模块结合使用--release(任何版本)


此处是包含以下内容的文件差异:


不允许使用
--release <从系统模块{0}导出包/ p>

我不能对基本原理发表评论,但从上面的引用来看,它适用于允许JDK 9与JDK 10一致地工作。 / p>

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天全站免登陆