Java的不同Nashorn引擎<15并且> = 15? [英] Different Nashorn engine for Java < 15 and >= 15?

查看:84
本文介绍了Java的不同Nashorn引擎<15并且> = 15?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如另一个 scriptEngine = try {//Java> = 15org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory().scriptEngine} catch(e:UnsupportedClassVersionError){//Java<15@抑制("DEPRECATION")jdk.nashorn.api.scripting.NashornScriptEngineFactory().scriptEngine}

但是似乎未捕获到错误.堆栈跟踪如下:

  java.lang.UnsupportedClassVersionError:org/openjdk/nashorn/api/linker/NashornLinkerExporter已由Java Runtime的最新版本(类文件版本59.0)进行编译,此版本的Java Runtime仅可识别类文件版本最高为55.0 

我还尝试捕获 NoClassDefFoundError ,将先前的try/catch反转(加载Java <15 Nashorn,如果不存在,则加载独立的),但错误是相同的./p>

看起来Java抛出了错误<15 Nashorn本身.

Nashorn维护者在这里!我刚刚发布了 Nashorn 15.2 ,与15.1.1相同,但现在已使用Java 11进行编译.这意味着您现在可以将独立的Nashorn与Java 11及更高版本一起使用,而不必切换为<15和> =15.我编写了页面解释如何在同时具有内置Nashorn和独立Nashorn的Java 11-14上使用它.

I'm trying to find a workaround for Nashorn to be compatible with every version of Java from 1.8 upwards as said in another question I asked earlier.
I'm currently trying to catch UnsupportedClassVersionError in order to find out if the system is able to run the standalone Nashorn for Java 15 like this (Kotlin code):

scriptEngine = try {
            
    // Java >= 15

    org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory().scriptEngine
} catch(e: UnsupportedClassVersionError) {

    // Java < 15

    @Suppress("DEPRECATION")
    jdk.nashorn.api.scripting.NashornScriptEngineFactory().scriptEngine
}

However it looks like the error is not caught. The stack trace is as follows:

java.lang.UnsupportedClassVersionError: org/openjdk/nashorn/api/linker/NashornLinkerExporter has been compiled by a more recent version of the Java Runtime (class file version 59.0), this version of the Java Runtime only recognizes class file versions up to 55.0

I also have tried to catch NoClassDefFoundError inverting the previous try/catch (load Java < 15 Nashorn, if it doesn't exist load the standalone one) but the error is the same.

Edit: looks like the error is thrown by the Java < 15 Nashorn itself.

解决方案

Nashorn maintainer here! I just released Nashorn 15.2, which is identical to 15.1.1 but is now compiled with Java 11. This means you can now use standalone Nashorn with Java 11 and above and don't have to switch for < 15 and >= 15. I wrote a page to explain how to use it on Java 11-14 where both built-in and standalone Nashorn are present.

这篇关于Java的不同Nashorn引擎&lt;15并且&gt; = 15?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆