4

I'm using Scala / Mongo / Casbah / Salat / Play2 and when i try to use Salat it seems it has a dependency to Scalap.

It works fine when running the application with play run but with play start i get the following stack:

[info] application - Can't create user 
java.lang.NoClassDefFoundError: scala/tools/nsc/util/ClassPath$JavaContext
    at scala.tools.scalap.scalax.rules.scalasig.ScalaSigParser$.scalaSigFromAttribute(ScalaSig.scala:35) ~[scalap-2.9.1.jar:na]
    at scala.tools.scalap.scalax.rules.scalasig.ScalaSigParser$.parse(ScalaSig.scala:38) ~[scalap-2.9.1.jar:na]
    at com.novus.salat.util.ScalaSigUtil$$anonfun$parseScalaSig0$2.apply(ScalaSigUtil.scala:73) ~[salat-util_2.9.1-0.0.8-SNAPSHOT.jar:0.0.8-SNAPSHOT]
    at com.novus.salat.util.ScalaSigUtil$$anonfun$parseScalaSig0$2.apply(ScalaSigUtil.scala:73) ~[salat-util_2.9.1-0.0.8-SNAPSHOT.jar:0.0.8-SNAPSHOT]
    at scala.Option.map(Option.scala:133) ~[scala-library.jar:na]
    at com.novus.salat.util.ScalaSigUtil$.parseScalaSig0(ScalaSigUtil.scala:73) ~[salat-util_2.9.1-0.0.8-SNAPSHOT.jar:0.0.8-SNAPSHOT]
Caused by: java.lang.ClassNotFoundException: scala.tools.nsc.util.ClassPath$JavaContext
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366) ~[na:1.7.0_01]
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355) ~[na:1.7.0_01]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_01]
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354) ~[na:1.7.0_01]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423) ~[na:1.7.0_01]
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) ~[na:1.7.0_01]

scala/tools/nsc/util/ClassPath$JavaContext is in the Scala compiler project so i added the SBT dependency:

"org.scala-lang" % "scala-compiler" % "2.9.1"

Now it works fine with play start too.

But is it normal to have to run my project with a runtime dependency to the scala compiler? And why does it work with play run without the scala compiler dependency? Is it automatically embedded when not running in production mode?

Thanks

Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
  • 1
    possible duplicate of [NoClassDefFoundError => ClassPath$JavaContext when using play start](http://stackoverflow.com/questions/11819518/noclassdeffounderror-classpathjavacontext-when-using-play-start) – drexin Aug 06 '12 at 08:34

2 Answers2

4

Actually Scalap depends on the Scala compiler:

<dependencies>
    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-compiler</artifactId>
        <version>2.9.0.RC4</version>
    </dependency>
</dependencies>

http://www.jarvana.com/jarvana/inspect-pom/org/scala-lang/scalap/2.9.0.RC4/scalap-2.9.0.RC4.pom

I was having the problem because temporary my dependencies were handled manually and not by SBT.

Now i manage them by SBT and it works fine... but the compiler is still retrieved as a transitive dependency with Salat as initial dependency...

It's strange to have the compiler at runtime but it works...

Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
3

This happens for two reasons:

  • If you are working in dev mode, your classes are continuosly recompiled. So you need a compiler.

  • If you use the stage mode, the classes are compiled once forever, but this is done internally . If not you would have to provide a reference to the scala compiler, which could replace the scala compiler dependency.

Edmondo
  • 19,559
  • 13
  • 62
  • 115
  • Ok so it should explain why it works fine with play run, but actually with play start i'm in production mode, everything is compiler before so why would i need a compiler dependency? – Sebastien Lorber Aug 06 '12 at 08:45
  • Like it's described here: https://github.com/playframework/Play20/wiki/Production With start or stage the result is the same – Sebastien Lorber Aug 06 '12 at 09:42
  • Actually the play server compiles well, starts well. It's only when using Salat, which is using Scalap, that a get the following stack. Isn't Scalap usable at runtime? Isn't Scala compiler supposed to not be in the runtime? Thus why make such a dependency? – Sebastien Lorber Aug 06 '12 at 12:44
  • Scalap depends on Scala compiler. – Edmondo Aug 06 '12 at 12:45