【发布时间】:2011-09-30 21:36:08
【问题描述】:
我正在使用 sbt 0.11 和 Scala 2.9.1(它似乎在同一线程中评估 REPL 行)。在我的 build.sbt 我有:
initialCommands in console := """
println(Thread.currentThread)
println(Thread.currentThread.getContextClassLoader)
ru.circumflex.orm.Context.get() // reads my src/main/resources/cx.properties
"""
Context.get() 加载资源:
val bundle = ResourceBundle.getBundle(
"cx", Locale.getDefault, Thread.currentThread.getContextClassLoader)
这会导致错误(REPL 似乎在 stdout/stderr 之后缓冲了自己的输出):
> console
[info] No CoffeeScripts to compile
[info] Starting scala interpreter...
[info]
Thread[run-main,5,trap.exit]
sun.misc.Launcher$AppClassLoader@12360be0
14:17:44.003 [run-main] ERROR ru.circumflex.core - Could not read configuration parameters from cx.properties.
res0: ru.circumflex.core.Context = ctx()
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> Thread.currentThread
res1: java.lang.Thread = Thread[run-main,5,trap.exit]
scala> Thread.currentThread.getContextClassLoader
res2: java.lang.ClassLoader = scala.tools.nsc.interpreter.IMain$$anon$2@3a8393ef
删除最后一个 initialCommand 行并在 REPL 中运行它不会导致任何错误,因为此时资源是可见的。
有关如何处理此问题并使我的应用程序资源可供 initialCommands 访问的任何提示?
【问题讨论】:
标签: scala sbt read-eval-print-loop