代码:
object HelloWorld{
def main(args: Array[String]){
println("Hello, world!")
}
}
环境变量:
在窗户上:
JAVA_HOME = C:\Program Files\Java\jdk1.7.0_07
CLASSPATH = .;C:\Program Files\Java\jdk1.7.0_07\lib;C:\Software\scala-2.9.2\lib
PATH = %PATH%;C:\Program Files\Java\jdk1.7.0_07\bin;C:\Software\scala-2.9.2\bin
SCALA_HOME = C:\Software\scala-2.9.2
脚步:
scala HelloWorld.scala //Correctly output Hello,world!
scalac HelloWorld.scala //No Compilation error
java HelloWorld //Errors shown below
错误:
Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at HelloWorld.main(HelloWorld.scala)
Caused by: java.lang.ClassNotFoundException: scala.ScalaObject
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 13 more
很抱歉这个菜鸟问题,但我已经尝试了很长时间,但无法让它发挥作用。
试图scala -save
jar文件并运行java -jar
;还尝试更改类路径,例如添加scala-library.jar
,但仍然无法正常工作。