The GraalVM Polyglot API allows to embed and run code from guest languages in JVM-based host applications. I'm using native-image
and additionally installed python
so I can evaluate js
and python
scripts successfully from my java application via
context.eval("js", "print('Hello JavaScript!');")
context.eval("python", "print('Hello Python!');")
It works just fine. However, if I try to evaluate the kotlin script in a similar way -
context.eval("kotlin", "data class Company(val name: String, val year: Long);")
then it fails with
Exception in thread "main" java.lang.IllegalArgumentException: A language with id 'kotlin' is not installed. Installed languages are: [js, llvm, python].
at com.oracle.truffle.polyglot.PolyglotEngineException.illegalArgument(PolyglotEngineException.java:128)
at com.oracle.truffle.polyglot.PolyglotEngineImpl.requirePublicLanguage(PolyglotEngineImpl.java:867)
at com.oracle.truffle.polyglot.PolyglotContextImpl.requirePublicLanguage(PolyglotContextImpl.java:899)
at com.oracle.truffle.polyglot.PolyglotContextImpl.eval(PolyglotContextImpl.java:868)
at org.graalvm.polyglot.Context.eval(Context.java:345)
at org.graalvm.polyglot.Context.eval(Context.java:371)
I understand that it states that only [js, llvm, python]
are available but I wonder whether it's possible to add anything to be able to evaluate kotlin
script the similar way as well or not ? Or probably there is another way to evaluate a dynamic kotlin script at runtime from java application ?
Thank you.