GraalJSEngineFactory 无法实例化。

huangapple go评论75阅读模式
英文:

GraalJSEngineFactory could not be instantiated

问题

以下是我尝试运行的代码:

ScriptEngine graaljsEngine = new ScriptEngineManager().getEngineByName("graal.js");
if (graaljsEngine == null) 
{
    System.out.println("未找到Graal.js");
    return null;
}
try 
{
    System.out.println(graaljsEngine.eval("IncomingMessageString"));
} 
catch (ScriptException e) 
{
    e.printStackTrace();
}

使用的JAR包:

1: truffle-api-20.2.0.jar
2: js-scriptengine-20.2.0.jar
3: js-20.2.0.jar
4: graal-sdk-20.2.0.jar
5: compiler-20.2.0.jar

在尝试执行上述代码时,我遇到了以下错误:

ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider
com.oracle.truffle.js.scriptengine.GraalJSEngineFactory 无法实例化

我尝试使用以下虚拟机选项来运行代码:

-Dpolyglot.inspect.Secure=false

但仍未解决问题。

英文:

I am new to Graal. I am referring this document. I am using JDK 11.

Below is the code I am trying to run:

ScriptEngine graaljsEngine = new ScriptEngineManager().getEngineByName("graal.js");
if (graaljsEngine == null) 
{
    System.out.println("Graal.js not found");
    return null;
}
try 
{
    System.out.println(graaljsEngine.eval("IncomingMessageString"));
} 
catch (ScriptException e) 
{
    e.printStackTrace();
}

jars being used:

1: truffle-api-20.2.0.jar    
2: js-scriptengine-20.2.0.jar    
3: js-20.2.0.jar    
4: graal-sdk-20.2.0.jar    
5: compiler-20.2.0.jar

When trying to execute the code above, I am running into the follow error:

> ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider
com.oracle.truffle.js.scriptengine.GraalJSEngineFactory could not be instantiated

I have tried running the code with the following VM options:

-Dpolyglot.inspect.Secure=false

it still doesn't resolve the issue.

答案1

得分: 1

最终不得不使用构建自动化来解决问题,这很奇怪,因为我除了已经手动添加的jar文件之外,没有提及任何新的jar文件。

如果使用Gradle,请将以下内容放入您的build.gradle文件中:

dependencies {
    compile group: 'org.graalvm.js', name: 'js', version: '20.2.0'
    compile group: 'org.graalvm.js', name: 'js-scriptengine', version: '20.2.0'
    compile group: 'org.graalvm.sdk', name: 'graal-sdk', version: '20.2.0'
    compile group: 'org.graalvm.truffle', name: 'truffle-api', version: '20.2.0'
}

如果使用Maven,请将以下内容放入您的pom.xml文件中:

<properties>
    <graalvm.version>20.2.0</graalvm.version>
    <compiler.dir>${project.build.directory}/compiler</compiler.dir>
</properties>
<dependencies>
    <dependency>
        <groupId>org.graalvm.sdk</groupId>
        <artifactId>graal-sdk</artifactId>
        <version>${graalvm.version}</version>
    </dependency>
    <dependency>
        <groupId>org.graalvm.js</groupId>
        <artifactId>js</artifactId>
        <version>${graalvm.version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.graalvm.js</groupId>
        <artifactId>js-scriptengine</artifactId>
        <version>${graalvm.version}</version>
    </dependency>
    <dependency>
        <groupId>org.graalvm.tools</groupId>
        <artifactId>profiler</artifactId>
        <version>${graalvm.version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.graalvm.tools</groupId>
        <artifactId>chromeinspector</artifactId>
        <version>${graalvm.version}</version>
        <scope>runtime</scope>
    </dependency>
</dependencies>

在底层,我确定这些构建自动化工具正在通过获取其他缺失的jar来解决问题。我发现这个链接很有用:http://www.mosgrom.net/stuff/graalvm.html,但正如我所说,除非我使用Maven/Gradle进行依赖管理,否则仅通过解压GraalVM社区二进制文件或从Maven仓库手动添加必需的jar文件到我的Java项目中并不能解决问题。希望这能帮助其他遇到相同问题的人 :)。

英文:

Finally had to use build automation and that got it working , which is strange as I am not mentioning any new jars except for the ones I had already manually added .

If using gradle put this in your build.gradle and you are good:

dependencies {
    compile group: &#39;org.graalvm.js&#39;, name: &#39;js&#39;, version: &#39;20.2.0&#39;
    compile group: &#39;org.graalvm.js&#39;, name: &#39;js-scriptengine&#39;, version: &#39;20.2.0&#39;
    compile group: &#39;org.graalvm.sdk&#39;, name: &#39;graal-sdk&#39;, version: &#39;20.2.0&#39;
    compile group: &#39;org.graalvm.truffle&#39;, name: &#39;truffle-api&#39;, version: &#39;20.2.0&#39;
}

If using maven put this in your build.gradle and your are good:

    &lt;properties&gt;
        &lt;graalvm.version&gt;20.2.0&lt;/graalvm.version&gt;
        &lt;compiler.dir&gt;${project.build.directory}/compiler&lt;/compiler.dir&gt;
    &lt;/properties&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.graalvm.sdk&lt;/groupId&gt;
            &lt;artifactId&gt;graal-sdk&lt;/artifactId&gt;
            &lt;version&gt;${graalvm.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.graalvm.js&lt;/groupId&gt;
            &lt;artifactId&gt;js&lt;/artifactId&gt;
            &lt;version&gt;${graalvm.version}&lt;/version&gt;
            &lt;scope&gt;runtime&lt;/scope&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.graalvm.js&lt;/groupId&gt;
            &lt;artifactId&gt;js-scriptengine&lt;/artifactId&gt;
            &lt;version&gt;${graalvm.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.graalvm.tools&lt;/groupId&gt;
            &lt;artifactId&gt;profiler&lt;/artifactId&gt;
            &lt;version&gt;${graalvm.version}&lt;/version&gt;
            &lt;scope&gt;runtime&lt;/scope&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.graalvm.tools&lt;/groupId&gt;
            &lt;artifactId&gt;chromeinspector&lt;/artifactId&gt;
            &lt;version&gt;${graalvm.version}&lt;/version&gt;
            &lt;scope&gt;runtime&lt;/scope&gt;
        &lt;/dependency&gt;

Under the hood I am sure these build automation tools are resolving the issue by getting other missing jars. I found this link useful : http://www.mosgrom.net/stuff/graalvm.html but as I said just manually adding the requisite jars by unzipping graalvm community binary or from maven repo to my java project didn't resolve the issue unless I used maven/gradle for dependency management . Hope that helps anyone else with same issue GraalJSEngineFactory 无法实例化。 .

答案2

得分: -1

最简单高效的解决方案是在GraalVM发行版上运行您的代码:只需将您的JAVA_HOME更改为GraalVM的路径,或在您的IDE中更改Java的主目录设置。

如果您坚持使用另一个JDK发行版,请参考https://www.graalvm.org/reference-manual/js/RunOnJDK/。

英文:

The simplest and most efficient solution is to run your code on GraalVM distribution: just change your JAVA_HOME to the path to GraalVM or change the Java home setting in your IDE.

If you insist on using another JDK distribution, then take a look at https://www.graalvm.org/reference-manual/js/RunOnJDK/

huangapple
  • 本文由 发表于 2020年9月25日 03:24:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/64053102.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定