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

Fundamental error with scalatest 1.2: java.lang.NoClassDefFoundError: scala/ScalaObject

6 replies
Kenneth McDonald
Joined: 2009-01-11,
User offline. Last seen 42 years 45 weeks ago.

In order to track down a problem I'm having with scalatest under sbt, I'm trying to run scalatest from the command line, via:

scala -classpath scalatest-1.2.jar org.scalatest.tools.Runner -p "scalatest-1.2-tests.jar" -o -s org.scalatest.SuiteSuite

executed while in a newly-downloaded scalatest 1.2 directory. When I do this, I get the following error/stack trace:

Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getMethod0(Class.java:2670)
at java.lang.Class.getMethod(Class.java:1603)
at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:77)
at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:86)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:83)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
Caused by: java.lang.ClassNotFoundException: scala.ScalaObject
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 20 more

My version of scala is up to date and recognizes scala.ScalaObject:

Macintosh-7:scalatest-1.2 Ken$ scala
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) Client VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.

scala> new scala.ScalaObject
:6: error: trait ScalaObject is abstract; cannot be instantiated
new scala.ScalaObject
^

Any ideas as to what might be causing this? Not having a working test framework is no fun at all.

Thanks,
Ken

Derek Williams
Joined: 2009-06-13,
User offline. Last seen 42 years 45 weeks ago.
Re: Fundamental error with scalatest 1.2: java.lang.NoClassDefF

Probably doesn't help, but running the exact same command executes
fine on my machine, this is under Linux though. At least what you are
doing should work, so it doesn't appear you are doing anything wrong.

To simplify things, what about if you just run:

scala -classpath scalatest-1.2.jar

that should give you the REPL and you should be able to "import org.scalatest._"

Bill Venners
Joined: 2008-12-18,
User offline. Last seen 31 weeks 5 days ago.
Re: Fundamental error with scalatest 1.2: java.lang.NoClassDefF

Hi Kenneth,

I just redownloaded the 1.2 jar and also executed the command and it
worked fine. It acts like it can't find the Scala library, but if you
can say "scala" on the command line I don't know why it wouldn't find
the Scala library. Something else you could try is to say java instead
of scala and put the scala library on the classpath.

Bill

On Sat, Jan 22, 2011 at 11:51 AM, Kenneth McDonald
wrote:
> In order to track down a problem I'm having with scalatest under sbt, I'm trying to run scalatest from the command line, via:
>
>        scala -classpath scalatest-1.2.jar org.scalatest.tools.Runner -p "scalatest-1.2-tests.jar" -o -s org.scalatest.SuiteSuite
>
> executed while in a newly-downloaded scalatest 1.2 directory. When I do this, I get the following error/stack trace:
>
> Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject
>        at java.lang.ClassLoader.defineClass1(Native Method)
>        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
>        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
>        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
>        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
>        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
>        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
>        at java.security.AccessController.doPrivileged(Native Method)
>        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
>        at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
>        at java.lang.Class.getDeclaredMethods0(Native Method)
>        at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
>        at java.lang.Class.getMethod0(Class.java:2670)
>        at java.lang.Class.getMethod(Class.java:1603)
>        at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:77)
>        at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:86)
>        at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:83)
>        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
> Caused by: java.lang.ClassNotFoundException: scala.ScalaObject
>        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
>        at java.security.AccessController.doPrivileged(Native Method)
>        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
>        at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
>        ... 20 more
>
> My version of scala is up to date and recognizes scala.ScalaObject:
>
>        Macintosh-7:scalatest-1.2 Ken$ scala
>        Welcome to Scala version 2.8.1.final (Java HotSpot(TM) Client VM, Java 1.6.0_22).
>        Type in expressions to have them evaluated.
>        Type :help for more information.
>
>        scala> new scala.ScalaObject
>        :6: error: trait ScalaObject is abstract; cannot be instantiated
>               new scala.ScalaObject
>               ^
>
> Any ideas as to what might be causing this? Not having a working test framework is no fun at all.
>
>
> Thanks,
> Ken
>
>

Kenneth McDonald
Joined: 2009-01-11,
User offline. Last seen 42 years 45 weeks ago.
Re: Fundamental error with scalatest 1.2: java.lang.NoClassDef

I tracked down the problem; it turned out that scalatest-1.2 was on the java path more than once, due to some fiddling I'd done in the past to have IDEA recognize name 'FunSuite'. (I'd put a link to scalatest in the Java Extensions dir.) I'm not really surprised that having the same jar in scope more than once could cause an error, but am somewhat surprised at the nature of the error. Oh well, live and learn.

I've taken scalatest out of Extensions (and also cleaned up my CLASSPATH env var), and now scalatest and sbt targets work tickety-boo, including the test phase. FunSuite still shows up as an error in IDEA, but I can live with that for now.

Thanks,
Ken

On Jan 22, 2011, at 1:51 PM, Kenneth McDonald wrote:

> In order to track down a problem I'm having with scalatest under sbt, I'm trying to run scalatest from the command line, via:
>
> scala -classpath scalatest-1.2.jar org.scalatest.tools.Runner -p "scalatest-1.2-tests.jar" -o -s org.scalatest.SuiteSuite
>
> executed while in a newly-downloaded scalatest 1.2 directory. When I do this, I get the following error/stack trace:
>
> Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject
> at java.lang.ClassLoader.defineClass1(Native Method)
> at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
> at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
> at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
> at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
> at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
> at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
> at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
> at java.lang.Class.getDeclaredMethods0(Native Method)
> at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
> at java.lang.Class.getMethod0(Class.java:2670)
> at java.lang.Class.getMethod(Class.java:1603)
> at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:77)
> at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:86)
> at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:83)
> at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
> Caused by: java.lang.ClassNotFoundException: scala.ScalaObject
> at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
> at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
> ... 20 more
>
> My version of scala is up to date and recognizes scala.ScalaObject:
>
> Macintosh-7:scalatest-1.2 Ken$ scala
> Welcome to Scala version 2.8.1.final (Java HotSpot(TM) Client VM, Java 1.6.0_22).
> Type in expressions to have them evaluated.
> Type :help for more information.
>
> scala> new scala.ScalaObject
> :6: error: trait ScalaObject is abstract; cannot be instantiated
> new scala.ScalaObject
> ^
>
> Any ideas as to what might be causing this? Not having a working test framework is no fun at all.
>
>
> Thanks,
> Ken
>

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Fundamental error with scalatest 1.2: java.lang.NoClassDefF
Good to know! I have seen problems like this in the past, and most of them I could track to code compiled with different scala versions. However, there was one case where that wasn't true, and it is quite possible this was the problem.

On Sat, Jan 22, 2011 at 23:28, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
I tracked down the problem; it turned out that scalatest-1.2 was on the java path more than once, due to some fiddling I'd done in the past to have IDEA recognize name 'FunSuite'. (I'd put a link to scalatest in the Java Extensions dir.) I'm not really surprised that having the same jar in scope more than once could cause an error, but am somewhat surprised at the nature of the error. Oh well, live and learn.

I've taken scalatest out of Extensions (and also cleaned up my CLASSPATH env var), and now scalatest and sbt targets work tickety-boo, including the test phase. FunSuite still shows up as an error in IDEA, but I can live with that for now.

Thanks,
Ken

On Jan 22, 2011, at 1:51 PM, Kenneth McDonald wrote:

> In order to track down a problem I'm having with scalatest under sbt, I'm trying to run scalatest from the command line, via:
>
>       scala -classpath scalatest-1.2.jar org.scalatest.tools.Runner -p "scalatest-1.2-tests.jar" -o -s org.scalatest.SuiteSuite
>
> executed while in a newly-downloaded scalatest 1.2 directory. When I do this, I get the following error/stack trace:
>
> Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject
>        at java.lang.ClassLoader.defineClass1(Native Method)
>        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
>        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
>        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
>        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
>        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
>        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
>        at java.security.AccessController.doPrivileged(Native Method)
>        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
>        at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
>        at java.lang.Class.getDeclaredMethods0(Native Method)
>        at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
>        at java.lang.Class.getMethod0(Class.java:2670)
>        at java.lang.Class.getMethod(Class.java:1603)
>        at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:77)
>        at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:86)
>        at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:83)
>        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
> Caused by: java.lang.ClassNotFoundException: scala.ScalaObject
>        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
>        at java.security.AccessController.doPrivileged(Native Method)
>        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
>        at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
>        ... 20 more
>
> My version of scala is up to date and recognizes scala.ScalaObject:
>
>       Macintosh-7:scalatest-1.2 Ken$ scala
>       Welcome to Scala version 2.8.1.final (Java HotSpot(TM) Client VM, Java 1.6.0_22).
>       Type in expressions to have them evaluated.
>       Type :help for more information.
>
>       scala> new scala.ScalaObject
>       <console>:6: error: trait ScalaObject is abstract; cannot be instantiated
>              new scala.ScalaObject
>              ^
>
> Any ideas as to what might be causing this? Not having a working test framework is no fun at all.
>
>
> Thanks,
> Ken
>




--
Daniel C. Sobral

I travel to the future all the time.
ijuma
Joined: 2008-08-20,
User offline. Last seen 22 weeks 3 days ago.
Re: Fundamental error with scalatest 1.2: java.lang.NoClassDefF

On Sun, Jan 23, 2011 at 1:28 AM, Kenneth McDonald
wrote:
> I tracked down the problem; it turned out that scalatest-1.2 was on the java path more than once, due to some fiddling I'd done in the past to have IDEA recognize name 'FunSuite'. (I'd put a link to scalatest in the Java Extensions dir.) I'm not really surprised that having the same jar in scope more than once could cause an error, but am somewhat surprised at the nature of the error. Oh well, live and learn.

The issue is not that it appears twice in the java classpath. The
issue is that scalatest is in the Java extensions directory. That
causes a different classloader to be used causing issues because the
Scala library is not visible in that classloader.

Best,
Ismael

Kenneth McDonald
Joined: 2009-01-11,
User offline. Last seen 42 years 45 weeks ago.
Re: Fundamental error with scalatest 1.2: java.lang.NoClassDefF

Thanks, that's useful info. Classloaders are something I'm planning on learning more about in the future, but learning Scala thoroughly is a higher priority.

Cheers,
Ken

On Jan 23, 2011, at 10:38 AM, Ismael Juma wrote:

> On Sun, Jan 23, 2011 at 1:28 AM, Kenneth McDonald
> wrote:
>> I tracked down the problem; it turned out that scalatest-1.2 was on the java path more than once, due to some fiddling I'd done in the past to have IDEA recognize name 'FunSuite'. (I'd put a link to scalatest in the Java Extensions dir.) I'm not really surprised that having the same jar in scope more than once could cause an error, but am somewhat surprised at the nature of the error. Oh well, live and learn.
>
> The issue is not that it appears twice in the java classpath. The
> issue is that scalatest is in the Java extensions directory. That
> causes a different classloader to be used causing issues because the
> Scala library is not visible in that classloader.
>
> Best,
> Ismael

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