java release_Java 9编译器中的–release标志是什么?

不完全是。以下是

proposal的链接:

We defined a new command-line option, --release, which automatically configures the compiler to produce class files that will link against an implementation of the given platform version. For the platforms predefined in javac, --release N is equivalent to -source N -target N -bootclasspath . (emphasis mine)

所以不,它不等于-source N -target N。添加的原因在“动机”部分中说明:

javac provides two command line options, -source and -target, which can be used to select the version of the Java language accepted by the compiler and the version of the class files it produces, respectively. By default, however, javac compiles against the most-recent version of the platform APIs. The compiled program can therefore accidentally use APIs only available in the current version of the platform. Such programs cannot run on older versions of the platform, regardless of the values passed to the -source and `-target. options. This is a long-term usability pain point, since users expect that by using these options they’ll get class files that can run on the specified platform version.

简而言之,指定源代码和目标选项不足以进行交叉编译。由于默认情况下,javac针对最新的平台API进行编译,因此无法保证在较旧版本上运行。您还需要指定与旧版本对应的-bootclasspath选项,以便正确交叉编译。这将包括正确的API版本来编译,并允许在旧版本上执行。由于它经常被遗忘,所以决定添加一个命令行选项,它完成所有必要的事情以正确的交叉编译。

进一步阅读in the mailing list和Oracle Docs.原始错误是here提交的。请注意,自从该选项的集成之后,JDK版本已经捆绑了老版本的平台API的描述,在“风险和假设”一节中提到。这意味着您不需要安装在机器上的旧版本来交叉编译才能正常工作。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值