9

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)
    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?

1
  • Does it work with a different version of Scala/JDK? Commented Oct 10, 2011 at 15:14

1 Answer 1

21

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.

Sign up to request clarification or add additional context in comments.

4 Comments

This is one that keeps cropping up on OSX (and it seems fairly obvious that it is OSX in this case, given the value of JAVA_HOME)
@Brian hsu, thanks so much. I will try it soon. Based on the upvotes your answer got, I am sure it will work :-)
scala -nocompdaemon is a workaround: it doesn't start a background process for compilation.
@retronym this workaround doesn't solve the issue for me, (scala 2.11.7, Java 1.8.0_51), while answer does

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.