2010-08-15 10 views
8

Ich versuche, die folgenden Raketenabschuss-Anwendung auszuführen:Ausführen einer Scala App als Java-Anwendung

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

direkt von Java wie folgt aus:

java -cp scala-library.jar HelloWorld 

(offensichtlich nach mit scala compliling)

aber erhalten folgende Fehlermeldung:

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. 

Habe ich etwas Triviales übersehen, das ich tun muss, damit es funktioniert?

+0

Schauen Sie hier: http://en.wikipedia.org/wiki/Scala_%28programming_language%29, erwarte ich scala setzt korrekte Klassenpfade auf, dass von fehlt Java verwenden. –

Antwort

12

Vom 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.

Hinzufügen .: (oder .; unter Windows) zu Beginn Ihres Classpath sollte funktionieren.

+0

Danke, ich war mir sicher, dass es etwas Triviales war. :) –

0

Bitte versuchen:

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

+0

Sind Sie sicher, dass OP Windows verwendet? –

Verwandte Themen