views:

96

answers:

2

Here's an example:


import org.scala_tools.time.Imports._
...
val dt1 : DateTime = new DateTime ("2010-09-01T12:00Z")
val dt2 : DateTime = new DateTime ("2010-10-01T12:10Z")
println (dt1 < dt2) // This is the Main.scala:48 line mentioned in the stack trace below
...

If I compile and run it, I get


java.lang.NoClassDefFoundError: scala/Ordered
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    at org.scala_tools.time.JodaImplicits$class.RichReadableInstant(Implicits.scala:70)
    at org.scala_tools.time.Imports$.RichReadableInstant(Imports.scala:20)
    at myproject.Main$.main(Main.scala:48)
...

What may the reason be and how to fix this?

I use all (joda-time, SBT, Scala, SUN JVM) the latest stable releases (excl joda-time - I use its latest snapshot version).

+4  A: 

What Scala version are you using? Make sure the joda-time wrappers were compiled with the same Scala version.

Checking the current docs reveled that Ordered belongs to scala.math. There was a scala.Ordered but it was prior to 2.8. To be precise there still is a scala.Ordered - two in fact. One is a val and the other a type alias, both defined in the package object scala.

Seems the right joda-time wrapper is located at http://www.scala-tools.org/repo-releases/org/scala-tools/time/time_2.8.0/0.2/ - but it pure guessing.

pedrofurla
Exactly. I've replaced My scala-time jar with time_2.8.0-0.2.jar from your link and the problem disappeared. I was using time-2.8.0-SNAPSHOT-0.2-SNAPSHOT because I supposed it's newer, but now seems it isn't.
Ivan
+3  A: 

ClassNotFound errors for class from the Scala library are almost always caused by a version mismatch.

Either some of the classes from your own project were compiled with an older version of Scala (in which case you need to perform a clean build), or you're using a version of scala-tools/time that was compiled with an older version of Scala.

Kevin Wright