Trying to use Kotlin via javax.script (JSR 223) in a webapp


#1

Hi, I’m trying to use Kotlin (v1.2.60) packaged in a .war file deployed to WildFly (v13.0.0.Final), to be accessed through the javax.script API (JSR 223). WEB-INF/lib contains the jars from mvn packages “org.jetbrains.kotlin:kotlin-compiler-embeddable:1.2.60” and “org.jetbrains.kotlin:kotlin-script-util:1.2.60”.

Trying a simple eval like this:

ScriptEngine e = new KotlinJsr223JvmLocalScriptEngineFactory().getScriptEngine();
e.eval("1+1");

Gives this stacktrace:

java.lang.IllegalStateException: Resource not found: /kotlin/jvm/JvmStatic.class
	at deployment.kotlin_script_test.war//org.jetbrains.kotlin.script.util.impl.PathUtilKt.getResourcePathForClass(pathUtil.kt:76)
	at deployment.kotlin_script_test.war//org.jetbrains.kotlin.script.util.KotlinJars.getLib(context.kt:147)
	at deployment.kotlin_script_test.war//org.jetbrains.kotlin.script.util.KotlinJars$stdlibOrNull$2.invoke(context.kt:151)
	at deployment.kotlin_script_test.war//org.jetbrains.kotlin.script.util.KotlinJars$stdlibOrNull$2.invoke(context.kt:119)
	at deployment.kotlin_script_test.war//kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at deployment.kotlin_script_test.war//org.jetbrains.kotlin.script.util.KotlinJars.getStdlibOrNull(context.kt)
	at deployment.kotlin_script_test.war//org.jetbrains.kotlin.script.util.KotlinJars.getKotlinScriptStandardJars(context.kt:168)
	at deployment.kotlin_script_test.war//org.jetbrains.kotlin.script.util.ContextKt.scriptCompilationClasspathFromContextOrStlib(context.kt:109)
	at deployment.kotlin_script_test.war//org.jetbrains.kotlin.script.util.ContextKt.scriptCompilationClasspathFromContextOrStlib$default(context.kt:106)
	at deployment.kotlin_script_test.war//org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmDaemonLocalEvalScriptEngineFactory.getScriptEngine(KotlinJsr223ScriptEngineFactoryExamples.kt:46)
	at deployment.kotlin_script_test.war//kotlin.KotlinEvaluator.eval(KotlinEvaluator.java:10)

Running the code in a standalone app outside a web container with the same dependencies works fine.

Any ideas? What am I missing? Is the Kotlin script engine ready to be run inside a webapp?

Thanks, John


#2

I’ve tried to debug this and found that the method extractRoot from libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/impl/pathUtil.kt is called with an URL like this:

"vfs:/PATH_TO_EXPLODED_WAR/WEB-INF/lib/kotlin-stdlib-1.2.60.jar/kotlin/jvm/JvmStatic.class"

where “vfs” seems to be a special WildFly Virtual File System protocol which the extractRoot method cannot handle because it’s hard-wired to “jar” and “file”.

Any recommendations?