You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use Kotlin Scripting inside a Quarkus Application. However the Quarkus RuntimeClassloader seems to be insufficient to load the classes into the Scripting Engine. That is basically because it only loads classes that has been indexed at startup time.
1.) Start the Main class directly -> The script works. It outputs "Hello World!" and "A Model From Outside"
2.) run quarkus dev -> The output will be "Hello World" and a longish output with the message " ERROR Unresolved reference 'printName'. " at its end.
Something to add, there is a way that you can usually replace the used classloader like this:
val result = host.eval(StringScriptSource(""" printName()""".trimIndent()), ScriptWithMavenDepsConfiguration, ScriptEvaluationConfiguration {
implicitReceivers(modelFromOutside)
jvm {
baseClassLoader(FilteringClassLoader(Thread.currentThread().contextClassLoader, listOf("org.example", "java.lang")))
}
})
FilterClassLoader:
classFilteringClassLoader(
parent:ClassLoader,
valallowedPackages:List<String>
) : ClassLoader(parent) {
overridefunloadClass(name:String, resolve:Boolean): Class<*> {
if (allowedPackages.any { name.startsWith(it) }) {
returnsuper.loadClass(name, resolve)
}
throwClassNotFoundException("Class $name is not allowed")
}
}
I hoped that this does the trick but however this works in the plain java version but not with quarkus dev.
Is there a way that you kotlin people could assist here, or work together with quarkus?
The text was updated successfully, but these errors were encountered:
I am trying to use Kotlin Scripting inside a Quarkus Application. However the Quarkus RuntimeClassloader seems to be insufficient to load the classes into the Scripting Engine. That is basically because it only loads classes that has been indexed at startup time.
I also filed a ticket with quarkus:
quarkusio/quarkus#43271 (comment)
And i created a minimal reproducer for the problem:
https://github.com/ckosmowski/kotlin-script-reproducer
1.) Start the Main class directly -> The script works. It outputs "Hello World!" and "A Model From Outside"
2.) run quarkus dev -> The output will be "Hello World" and a longish output with the message " ERROR Unresolved reference 'printName'. " at its end.
Something to add, there is a way that you can usually replace the used classloader like this:
FilterClassLoader:
I hoped that this does the trick but however this works in the plain java version but not with quarkus dev.
Is there a way that you kotlin people could assist here, or work together with quarkus?
The text was updated successfully, but these errors were encountered: