java javascript引擎,8 Java的JavaScript引擎的向后兼容性

I am trying out Java 8 in my project and I am stuck in an error related to my build process.

I am using ANT scripts and at some point i am using some javascript (embeded into ANT) to do some build specific operations. The part of the script that is causing the error looks like below:

importClass(java.io.File);

importClass(java.io.FileReader);

...

]]>

The project is building fine with Java 7 or Java 6, but it gives me some errors when i am using Java 8. These errors are related to the upgrade of the JS engine.

In particular i am getting the following exception:

javax.script.ScriptException: ReferenceError: "importClass" is not defined in at line

After some googling i found out that it is related to the below issue in the JDK

I tried what is suggested in the comments but without luck.

How can I make Java 8 Nashorn engine to be compatible with the Rhino JS engine?

解决方案

One approach is to include

load("nashorn:mozilla_compat.js");

which supplies importClass.

On the other hand, you can use java.io.File, java.io.FileReader, ... directly without importing.

var File = java.io.File;

var FileReader = java.io.FileReader;

This is backward compatible with Rhino.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值