2010-08-15 169 views
8

我試圖運行下面的火箭發射應用:運行的Scala程序作爲一個Java應用程序

object HelloWorld { 
    def main(args: Array[String]) { 
     println("Hello World!") 
    } 
} 

直接從Java這樣的:

java -cp scala-library.jar HelloWorld 

(使用Scala compliling後明顯)

但出現以下錯誤:

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld 
Caused by: java.lang.ClassNotFoundException: HelloWorld 
     at java.net.URLClassLoader$1.run(Unknown Source) 
(...) 
Could not find the main class: HelloWorld. Program will exit. 

我是否監督了我需要做的任何微不足道的工作?

+0

看:http://en.wikipedia.org/wiki/Scala_%28programming_language%29,我希望斯卡拉樹立正確的類路徑,即使用Java失蹤。 – 2010-08-15 13:50:20

回答

12

Java documentation

The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.

添加.:(或Windows .;)到類路徑應該工作的開始。

+0

謝謝,我確定這是件小事。 :) – 2010-08-15 14:04:37

0

請嘗試:這裏

java -cp %SCALA_HOME%\lib\scala-library.jar;. HelloWorld

+0

你確定OP的使用Windows嗎? – 2014-07-24 10:46:09

相關問題