I need to compile and run a bunch of Kotlin script files (.kts) with certain classpath (JAR file, for example). It seems it is impossible with plain ScriptEngine, but I don’t understand what I should use.
You can still use JSR-223 script engine, preferably via kotlin-scripting-jsr223
module. To supply additional jars, you need to create the engine in a context of an URLClassLoader with your jars (set your classloader as thread context classloader).
But maybe this is not an easiest way to do it, check also the examples in the kotlin repo - kotlin/libraries/examples/scripting at master · JetBrains/kotlin · GitHub - maybe you’ll find more suitable approach.
1 Like