2010-08-15 114 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

相关问题