This page is no longer maintained — Please continue to the home page at www.scala-lang.org

java.lang.NoClassDefFoundError scala on JVM

2 replies
kminek
Joined: 2012-01-21,
User offline. Last seen 40 weeks 6 days ago.

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

 

Lars Hupel
Joined: 2010-06-23,
User offline. Last seen 44 weeks 3 days ago.
Re: java.lang.NoClassDefFoundError scala on JVM

> 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

sterg
Joined: 2009-10-06,
User offline. Last seen 2 years 39 weeks ago.
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
>
>
>
>

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland