0
我有一個簡單的Scala程序:斯卡拉+ Linux的:找不到主類罐子
main.scala
:
object Program {
def main(args: Array[String]) {
println("Hello World");
}
}
它編譯就好:
$ scalac -nowarn -d bin/scala.jar code/main.scala
當我運行它,我得到的錯誤:
$ scala bin/scala.jar
Exception in thread "main" java.lang.RuntimeException: Cannot find main class for jar: bin/scala.jar
at scala.sys.package$.error(package.scala:27)
at scala.tools.nsc.MainGenericRunner$$anonfun$runTarget$1$1.apply(MainGenericRunner.scala:62)
at scala.tools.nsc.MainGenericRunner$$anonfun$runTarget$1$1.apply(MainGenericRunner.scala:62)
at scala.Option.getOrElse(Option.scala:108)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:62)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:80)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:89)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
如果我在Windows上遵循相同的過程,程序執行得很好。我該如何解決?
謝謝Brian。當我在'scala.jar'的目錄中運行'scala Program'時,它說'無法弄清楚如何運行target:Program'。還有什麼我該做的? – wizulus
'scala.jar'是否包含'Program'的類文件?如果是這樣,請嘗試'scala -cp scala.jar程序'將'scala.jar'加載到類路徑中。 – Brian
工作正常!你會更新答案讓後代受益於這些知識嗎? – wizulus