Embedding Kotlin as scripting language in Java apps

For future searchers finding this topic, the key steps to get it to work are:

You need these libraries in your class path (in additon to stdlib):

  • kotlin-compiler
  • kotlin-script-util

In addition, you need a META-INF/services/javax.script.ScriptEngineFactory file in the classpath jar to tell the JSR223 script engine to use the Kotlin script engine. Just adding the above libraries does not do it (probably a security concern). The easiest way to just add the file to your own jar like from this example:

4 Likes