8 Java的JavaScript引擎的向后兼容性 [英] Java 8 Javascript Engine backwards compatibility
问题描述
我想出来的Java 8中我的项目,我被困在与我的构建过程中出现错误。
I am trying out Java 8 in my project and I am stuck in an error related to my build process.
我使用ANT脚本,并在某些时候我使用一些JavaScript(镶嵌成ANT)做一些构建特定的操作。这是导致错误的脚本的部分看起来像如下:
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:
<script language="javascript">
<![CDATA[
importClass(java.io.File);
importClass(java.io.FileReader);
...
]]>
</script>
该项目正在建设精细与Java 7或者Java 6,但它给了我一些错误,当我使用Java 8.这些错误都与JS引擎的升级。
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是不是在行定义
javax.script.ScriptException: ReferenceError: "importClass" is not defined in at line
在一些google搜索,我发现,这是关系到JDK的跌破发行
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.
如何让Java 8犀牛引擎与Rhino的JS引擎兼容?
How can I make Java 8 Nashorn engine to be compatible with the Rhino JS engine?
推荐答案
一种方法是包含
load("nashorn:mozilla_compat.js");
它提供importClass。
which supplies importClass.
在另一方面,你可以使用的java.io.File,java.io.FileReader,直接...不导入。
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;
这是向后兼容犀牛。
这篇关于8 Java的JavaScript引擎的向后兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!