圖作爲與最新的Java更新8u60 Java已經支持JSON使用犀牛腳本引擎映射converstion,我一直在嘗試使用示例代碼提供here檢出相同。但是,它給了我ScriptException下面的堆棧跟蹤。我使用Java 8u65來運行給定的代碼。ScriptException JSON轉換爲Java 8犀牛
堆棧跟蹤:
Exception in thread "main" javax.script.ScriptException: TypeError: Cannot call undefined in at line number 1 at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:455) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:439) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:401) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:397) at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:152) at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) at JSONTest.main(JSONTest.java:8) Caused by: :1 TypeError: Cannot call undefined at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57) at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:213)
對不起,我沒有得到你,你是什麼意思通過「Jar文件包含jdk」。你不覺得它所需要的只是運行時環境。 – dShringi
jdk庫被打包成jar文件。你需要包含你在類路徑中使用的每一個。對於我的CentOS的nashorn.jar文件是在這裏/usr/lib/jvm/java-1.8.0-openjdk/jre/lib/ext/nashorn.jar – PlatypusMaximus