问题
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
回答1:
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...
回答2:
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.
来源:https://stackoverflow.com/questions/11824881/why-do-i-need-scala-compiler-at-runtime-play2-salat-with-scalap-dependency