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.
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:
If using maven put this in your build.gradle and your are good:
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 :) .