Can't run any Scala application in the IDE

2,078 views
Skip to first unread message

Brian Payton

unread,
May 9, 2011, 4:22:18 PM5/9/11
to scala-i...@googlegroups.com
I'm having trouble running even the simplest Scala application in the Scala IDE for Eclipse.  For example, I created a Scala project, created a package "sandbox", then created the "Hello World" application:

package sandbox

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

When I run this as a Scala application, I get the following:

java.lang.NoClassDefFoundError: sandbox/HelloWorld
Caused by: java.lang.ClassNotFoundException: sandbox.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)

(Following some information in the online help for Scala IDE, I added "extends scala.Application" to the object declaration, but that didn't seem to make any difference.)

I'm using Eclipse 3.6.2 (Helios), Scala IDE beta 3, and Scala compiler 2.9.0.RC3

What am I doing wrong or what have I missed?  Sorry for the newbie question!



bryan hunt

unread,
May 10, 2011, 4:28:21 AM5/10/11
to scala-i...@googlegroups.com
Try Project -> Clean

Try right click on the project in the Package Explorer -> Add/Remove
Scala project nature.

You might have messed up the package location, try running the same
class sans name-space i.e without package declaration at the root of
your source path.

iulian dragos

unread,
May 10, 2011, 5:08:24 AM5/10/11
to scala-i...@googlegroups.com
On Mon, May 9, 2011 at 10:22 PM, Brian Payton <bgpa...@gmail.com> wrote:
> I'm having trouble running even the simplest Scala application in the Scala
> IDE for Eclipse.  For example, I created a Scala project, created a package
> "sandbox", then created the "Hello World" application:
>
> package sandbox
>
> object HelloWorld {
>     def main(args: Array[String]) {
>       println("Hello, world!")
>     }
>   }
>
> When I run this as a Scala application, I get the following:
>
> java.lang.NoClassDefFoundError: sandbox/HelloWorld
> Caused by: java.lang.ClassNotFoundException: sandbox.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)

Can you check in the run configuration that the scala library comes
first in the classpath? There was a bug about this some time ago, I'm
not sure it was (properly) fixed.

iulian

>
> (Following some information in the online help for Scala IDE, I added
> "extends scala.Application" to the object declaration, but that didn't seem
> to make any difference.)
>
> I'm using Eclipse 3.6.2 (Helios), Scala IDE beta 3, and Scala compiler
> 2.9.0.RC3
>
> What am I doing wrong or what have I missed?  Sorry for the newbie question!
>
>
>
>

--
« Je déteste la montagne, ça cache le paysage »
Alphonse Allais

Brian Payton

unread,
May 10, 2011, 12:59:15 PM5/10/11
to scala-i...@googlegroups.com
The classpath looked OK.  I tried removing and adding the Scala nature to the project, but it still didn't work.  I removed the package specification, but that didn't help either.  I copied the HelloWorld object to the default package and that sort-of worked.  (The application ran until I added another application in the default package, then neither of them ran anymore.)

I finally gave up, deleted the entire project, and started all over again.  Now things are working properly!

I think the problem was that I had originally created the project using the Scala IDE Beta 1, and something about the project itself wasn't right.  Creating an entirely new project using Beta 3 solved the issue.

Thanks for your help!

Hubert Plociniczak

unread,
May 10, 2011, 4:13:12 PM5/10/11
to Scala IDE User
I don't think this is the problem. That was manifesting itself usually
by saying that it couldn't find ScalaObject.

hubert

On May 10, 11:08 am, iulian dragos <jagua...@gmail.com> wrote:

Ingvar Bogdahn

unread,
Jun 5, 2011, 11:54:22 AM6/5/11
to scala-i...@googlegroups.com
Hello,

I have the same problem. I upgraded from Galileo, by downloading and installing everything new, but using a copy of my entire Galileo workspace.  May this cause problems? 
I did the things you suggested above, and if I'm make a Scala Object  it works once. But anything else doesn't. 
if I create a new class / object by right clicking the project,  there is only  "run configuration" in "Run as".
if I create a new class / object from main menu new, now in "run as" there is scala application, but when I click, I get a java.lang.NoClassDefFoundError

do you have any new idea how to solve this?

thank you

best
Ingvar
Reply all
Reply to author
Forward
0 new messages