我有一个具有以下结构的交叉构建项目:
<project root>
+- jvm
| +- src/main/scala/main.Scala
+- js
| +- src/main/scala/main.Scala
+- shared
+- src/main/scala/myLibrary.scala
+- src/main/resources/myjsfile.js
现在在我的 js main.Scala 文件中,我想读入 myjsfile.js。
我知道在标准 Scala JVM 项目中我可以执行以下操作:
val is = getClass.getClassLoader.getResourceAsStream("myjsfile.js")
val str = scala.io.Source.fromInputStream(is).mkString
现在我的问题是,如何使用当前的文件夹结构来做到这一点?
如果我运行以下 main.scala(js 版本):
package example
object Main extends App {
val is = getClass.getClassLoader.getResourceAsStream("")
val str = scala.io.Source.fromInputStream(is).mkString
println(str)
}
我收到以下错误:
org.scalajs.jsenv.ExternalJSRun$ClosedException: Termination was requested by user
[error] at org.scalajs.jsenv.ExternalJSRun$$anon$1.run(ExternalJSRun.scala:184)
[error] stack trace is suppressed; run last fooJS / Compile / run for the full output
[error] (fooJS / Compile / run) org.scalajs.jsenv.ExternalJSRun$ClosedException: Termination was requested by user
[error] Total time: 3 s, completed 25 Jun 2020, 10:56:05
[IJ]sbt:root>
我该如何克服这个错误?