我正在使用kotlin std-lib中的KotlinJsr223在运行时编译kotlin代码。
基本上概括问题,我有以下代码:
val engine = KotlinJsr223JvmLocalScriptEngineFactory().scriptEngine as KotlinJsr223JvmLocalScriptEngine
val kotlinScript = engine.compile("""println("Hello World")""") as KotlinJsr223JvmScriptEngineBase.CompiledKotlinScript
第二行运行(编译代码)后,将引发警告和RuntimException。
异常(exception)主线是:
WARN: Failed to initialize native filesystem for Windows
java.lang.RuntimeException: Could not find installation home path. Please make sure bin/idea.properties is present in the installation directory.
Looks like there's some problem in creating filesystem.
Full stack trace's gist is here,如果您要检查。
有办法解决问题吗?
编译不会退出应用程序,有点像警告。之后,像5秒钟一样的延迟,然后编译成功,但是5秒钟的中断和控制台警告仍然是某种威胁,需要加以解决。
我的运行时环境如下:
最佳答案
该问题仅在IDE中运行时才会发生,可以使用org.jetbrains.kotlin.cli.common.environment.setIdeaIoUseFallback
缓解。
可以在示例here中看到。
关于windows - Kotlin代码的运行时编译会引发RuntimeException(警告:无法为Windows初始化 native 文件系统),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61438356/