- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
java.lang.NoClassDefFoundError scala on JVM
Sun, 2012-01-22, 10:49
Hallo I am desperate :-(
Someone please help me ?
I start with scala and hello world.
My goal is to run the program scala on the JVM
Still have error "Noclassdeffounderror: HelloWorld".
for this easy program
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world!")
}
}
scala HelloWorld run OK
But return error for
C:\Users\oem\IdeaProjects\untitled7\src>java -cp scala-library.jar HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
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)
Could not find the main class: HelloWorld. Program will exit.
I have scala-library.jar in the same directory
What is the proper methods to run scala on the JVM? I tried many methods without success
Thank you
Sun, 2012-01-22, 13:31
#2
Re: java.lang.NoClassDefFoundError scala on JVM
Hello Daniel,
perhaps and my environment ScalaLab,
http://code.google.com/p/scalalab/
can help you to both learn Scala and to combine the basic Scala with
math libraries and plotting.
The particular example runs easily in ScalaLab as:
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world!")
}
}
HelloWorld.main(null)
Regards
Stergios
On Sun, 2012-01-22 at 10:49 +0100, daniel.kminek@centrum.cz wrote:
> Hallo I am desperate :-(
>
>
> Someone please help me ?
> I start with scala and hello world.
>
> My goal is to run the program scala on the JVM
>
>
>
>
> Still have error "Noclassdeffounderror: HelloWorld".
>
> for this easy program
>
>
> object HelloWorld {
> def main(args: Array[String]) {
> println("Hello, world!")
> }
> }
>
>
>
> scala HelloWorld run OK
>
>
>
> But return error for
>
>
>
> C:\Users\oem\IdeaProjects\untitled7\src>java -cp scala-library.jar
> HelloWorld
> Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
> Caused by: java.lang.ClassNotFoundException: HelloWorld
> 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)
> Could not find the main class: HelloWorld. Program will exit.
>
>
>
> I have scala-library.jar in the same directory
>
> What is the proper methods to run scala on the JVM? I tried many
> methods without success
>
> Thank you
>
>
>
>
> C:\Users\oem\IdeaProjects\untitled7\src>java -cp scala-library.jar
> HelloWorld
Try
java -cp path\to\scala-library.jar;. HelloWorld
The `.` will include the current directory. It is advisable that you put
the `scala-library.jar` somewhere else (maybe into a `lib` folder).
I also recommend that you have a look into "SBT", which is a build tool
for Scala. It automatically puts everything needed into the classpath
and even helps you to generate a JAR file which includes the Scala
library -- running Scala programs then reduces to
java -jar my-app.jar