简体   繁体   中英

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

I'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 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´sa CLASSPATH issue. You could try this:

$ scala -classpath . Hello

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM