我正在学习Scala而且我被困在hello world脚本中。
我的hello.scala是:
Console.println("Hello World")
我正在运行这样的脚本:
scala hello.scala
我得到一个奇怪的例外:
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
我的SCALA_HOME是/opt/scala-2.9.1.final
我的路径中有$ SCALA_HOME / bin
我的JAVA_HOME是:/usr/java/jdk1.7.0
这是我的设置问题还是由于Scala库和JDK1.7的某些问题?
答案 0 :(得分:21)
您的主机名似乎无法解析为正确的IP地址,因此scala无法连接到编译器服务。请检查/ etc / hosts文件,它应该有如下记录:
127.0.0.1 salil
设置主机名/ IP映射后,可以使用ping salil
命令确认设置是否正确。