Mac上的Scala - 无法弄清楚如何运行目标?

时间:2012-03-20 20:21:22

标签: scala

我正在尝试运行导入scala.IO.Source的Scala脚本,每次尝试运行时都会抛出异常,如下所示:

Exception in thread "main" java.lang.RuntimeException: Cannot figure out how to run target: countchars1.scala
    at scala.sys.package$.error(package.scala:27)
    at scala.tools.nsc.GenericRunnerCommand.scala$tools$nsc$GenericRunnerCommand$$guessHowToRun(GenericRunnerCommand.scala:38)
    at scala.tools.nsc.GenericRunnerCommand$$anonfun$2.apply(GenericRunnerCommand.scala:48)
    at scala.tools.nsc.GenericRunnerCommand$$anonfun$2.apply(GenericRunnerCommand.scala:48)
    at scala.Option.getOrElse(Option.scala:108)
    at scala.tools.nsc.GenericRunnerCommand.<init>(GenericRunnerCommand.scala:48)
    at scala.tools.nsc.GenericRunnerCommand.<init>(GenericRunnerCommand.scala:17)
    at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:33)
    at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:89)
    at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

我认为这是由于我的Path或Classpath设置,但我不确定这些是什么或需要设置的位置。我已尝试修改.bash_profile无效,并尝试将.profile添加到我认为必需的PATH设置中,但似乎没有直接的答案我可以找到

我目前正在Mac OSX 10.6上运行Scala 2.9.1。我试图从“Scala编程”运行的脚本如下:

import scala.io.Source

if (args.length > 0) {
  for (line <- Source.fromFile(args(0)).getLines)
print(line.length +" "+ line)
}
else
Console.err.println("Please enter filename")

当我在终端窗口中输入以下内容时遇到异常:

$ scala countchars1.scala countchars1.scala

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

通过使用以下说明设置JAVA_HOME变量来管理解决问题:

http://decoding.wordpress.com/2010/02/26/how-to-set-the-java_home-variable-in-mac-os-x-snow-leopard/