开发者

Scala 2.9 can't run "hello world" sample on Windows XP

I'开发者_StackOverflow社区m trying to run HelloWorld sample with scala 2.9.1 final on Windows XP:

object HelloWorld extends App {
  println("Hello, World!")
}

File is saved as Hello.scala.

When I run scalac Hello.scala, it's ok.

When I run scala Hello, it writes:

"Exception in thread "main" java.lang.RuntimeException: Cannot figure out how to run target" 

It's ridiculous, my echo %PATH% contains:

C:\Program Files\Java\jdk1.6.0_25\bin;
C:\Program Files\Java\jdk1.6.0_25\jre\lib;
C:\Program Files\Java\jdk1.6.0_25\lib;
C:\Program Files\scala\bin

so everything seems to be in classpath.

Running scala -classpath "%PATH%;." Hello doesn't help either.

Please help.


Shouldn't it be scala HelloWorld?

I can repro your problem on Mac too:

$ scalac hello.scala 
$ scala HelloWorld
Hello, World!
$ scala Hello
Exception in thread "main" java.lang.RuntimeException: Cannot figure out how to run target: Hello
    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:109)
    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)

scala expects either a class name or a source name. scala Hello doesn't resolve to either of them.


I think it´s a CLASSPATH issue. You could try this:

$ scala -classpath . Hello
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜