开发者

Scala: Hello World Script does not work

开发者 https://www.devze.com 2023-04-11 19:35 出处:网络
I am learning Scala and I am stuck at hello world script. My hello.scala is: Console.println(\"Hello World\")

I am learning Scala and I am stuck at hello world script.

My hello.scala is:

Console.println("Hello World")  

I am running the script like this:

scala hello.scala  

I get a weird exception:

java.net.UnknownHostException: salil: salil: Name or service not known
    at java.net.InetAddress.getLocalHost(InetAddress.java:1438)
    at scala.tools.nsc.io.Socket$.localhost(Socket.scala:38)
    at scala.tools.nsc.CompileSocket.getsock$1(CompileSocket.scala:169)
    at scala.tools.nsc.CompileSocket.getOrCreateSocket(CompileSocket.scala:184)
    at scala.tools.nsc.ScriptRunner.compileWithDaemon(ScriptRunner.scala:80)
    at scala.tools.nsc.ScriptRunner.compile$1(ScriptRunner.scala:123)
    at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply$mcZ$sp(ScriptRunner.scala:157)
    at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply(ScriptRunner.scala:131)
    at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply(ScriptRunner.scala:131)
    at scala.tools.nsc.util.package$.waitingForThreads(package.scala:26)
   开发者_如何学JAVA at scala.tools.nsc.ScriptRunner.withCompiledScript(ScriptRunner.scala:130)
    at scala.tools.nsc.ScriptRunner.runScript(ScriptRunner.scala:188)
    at scala.tools.nsc.ScriptRunner.runScriptAndCatch(ScriptRunner.scala:201)
    at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala

my SCALA_HOME is /opt/scala-2.9.1.final

and my Path has $SCALA_HOME/bin in it.

My JAVA_HOME is: /usr/java/jdk1.7.0

Is this an issue with my settings or is it due to some issue with Scala libraries and JDK1.7?


It seems your host name does not resolve to correct IP address, so scala could not connect to the compiler service. Please check your /etc/hosts file, it should have a a record like the following:

127.0.0.1    salil

After setting your hostname/IP mapping, you could use ping salil command to confirm that you the setting is correct.

0

精彩评论

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