Possible classloader problem with GraalVM in IntelliJ Plugin
Hello,
I'm trying to use the JavaScript engine of GraalVM inside an IntelliJ plugin, but I'm having the following error:
ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider com.oracle.truffle.js.scriptengine.GraalJSEngineFactory could not be instantiated
ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider de.lab4inf.math.scripting.javacc.JavaCCScriptEngineFactory could not be instantiated
2020-05-13 23:15:13,343 [ 13291] ERROR - llij.ide.plugins.PluginManager - No language and polyglot implementation was found on the classpath. Make sure the truffle-api.jar is on the classpath.
java.lang.IllegalStateException: No language and polyglot implementation was found on the classpath. Make sure the truffle-api.jar is on the classpath.
I'm adding the necessary dependencies in the build.gradle file:
compile group: 'org.graalvm.js', name: 'js', version: '20.0.0'
compile group: 'org.graalvm.js', name: 'js-scriptengine', version: '20.0.0'
And in External Libraries, truffle-api.jar appears.
The code I am trying to execute is:
Context.Builder contextBuilder = Context.newBuilder("js")
.allowHostAccess(HostAccess.ALL);
contextBuilder.allowExperimentalOptions(true).option("js.nashorn-compat", "true");
var engine = GraalJSScriptEngine.create(null, contextBuilder);
The error happens at GraalJSScriptEngine.create().
Thanks
Please sign in to leave a comment.
You'll probably need to hack classloader in your plugin's init code to make it work, see https://intellij-support.jetbrains.com/hc/en-us/community/posts/360002650839-Create-plugin-with-library-that-uses-ServiceLoader