Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala: Hello World Script does not work

Tags:

scala

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?

like image 656
Salil Avatar asked Oct 10 '11 14:10

Salil


People also ask

How do I run a scala program from the command line?

Here is the full process from the command line: evan@vbox ~> cat test. scala object test{ def main(args: Array[String]): Unit = println("Hello!") } evan@vbox ~> scalac test. scala evan@vbox ~> scala test Hello!


1 Answers

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.

like image 166
Brian Hsu Avatar answered Oct 30 '22 05:10

Brian Hsu