Imran/Malic
01/02/2020, 10:14 AMval classpath: List<File>
get() = ((Thread.currentThread().contextClassLoader as URLClassLoader).urLs ?: emptyArray<URL>()).toList()
.filterNot { it.path.contains("Java/JavaVirtualMachines") }
.map { Paths.get(it.toURI()).toFile() }
Any help is welcomed, how to add List<File>
to the classpath of an ScriptEngine. Usually if one creates a ScriptEngineManager with a classloader the classpath get’s added automatically to the ScriptEngines, but that is not the case here https://github.com/JetBrains/kotlin/blob/d73e6c855baa6066ba784bf2c77a1ca5854e70fc/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/jsr223/KotlinJsr223ScriptEngineFactoryExamples.kt#L33ilya.chernikov
01/07/2020, 11:53 AMwholeClasspath = true
instruct it to use whole extracted classpath unfiltered.
So, if it doesn't work for you, could you please elaborate.
Anyway, I'd suggest to use the new JSR-223 implementation - https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-scripting-jsr223/1.3.61 - in additional to other things, it has more reliable classpath extraction.Imran/Malic
01/07/2020, 12:04 PMImran/Malic
01/07/2020, 8:00 PMERROR USE_FIR: java.lang.NoSuchFieldError: USE_FIR
I defined this function:
fun evaluate(snip: String, classpath: List<File> = empty()): ResultWithDiagnostics<EvaluationResult> =
BasicJvmScriptingHost().eval(
script = snip.toScriptSource(),
compilationConfiguration = createJvmCompilationConfigurationFromTemplate<ScriptUtils> {
jvm {
updateClasspath(
scriptCompilationClasspathFromContext(wholeClasspath = true).plus(classpath).distinct()
)
}
},
evaluationConfiguration = ScriptEvaluationConfiguration {
jvm
}
)
it works fine in a main function, but doesnt in my project. Am I missing any dependencies?ilya.chernikov
01/08/2020, 11:14 AMkotlin
in your classpath. If so, I don't know why it doesn't work for you just looking at the code, some debugging is needed. If curios, you can step into the KotlinJsr223JvmLocalScriptEngine
constructor and check whether the passed classpath is the one you expect.ilya.chernikov
01/08/2020, 11:15 AMilya.chernikov
01/08/2020, 11:17 AMkotlin-scripting-jsr223
, and you can have a look at this test - https://github.com/JetBrains/kotlin/blob/master/libraries/scripting/jsr223-test/test/kotlin/script/experimental/jsr223/test/KotlinJsr223ScriptEngineIT.kt#L290 - to see how importing symbols from the classloader works.ilya.chernikov
01/08/2020, 11:21 AMdependency(JvmDependency(<list-of-classpath-files))
right after dependenciesFromCurrentContext
call in the host example you linked above. Or even instead of dependenciesFromCurrentContext
, if you want to control your dependencies explicitly.