SBT: libraryDependencies missing from classpath of jetty-run
I have set up a webapp project with sbt 0.10.1. One of the library dependencies is Jersey. My build.sbt file looks as follows:
seq(webSettings :_*)
scalaVersion := "2.8.1"
libraryDependencies ++= Seq(
"javax.ws.rs" % "jsr311-api" % "1.1" % "provided, jetty",
"com.sun.jersey" % "jersey-server" % "1.9" % "provided, jetty" from "http://download.java.net/maven/2/",
"org.eclipse.jetty" % "jetty-webapp" % "7.3.0.v20110203" % "jetty",
"ch.qos.logback" % "logback-classic" % "0.9.26",
"org.eclipse.jetty" % "jetty-servlet" % "7.3.0.v20110203"
)
On the sbt console I run reload, update, compile, prepare-webapp, jetty-run - in that order. Everything seems to be ok, except jetty-run. There I get a ClassNotFoundException
java.lang.ClassNotFoundException: com.sun.jersey.spi.container.serv开发者_C百科let.ServletContainer
This is because the Jersey library is not copied into target/webapp/WEB-INF/lib/ during jetty-run. So I guess there must be some flaw in my setup of build.sbt.
Does anyone have an idea what could be wrong here?
Thank you very much in advance! Michael
You have jersey dependency,
"com.sun.jersey" % "jersey-server" % "1.9" % "provided, jetty"
from "http://download.java.net/maven/2/"
but when you check the directory under the path you've provided,
http://download.java.net/maven/2/com/sun/jersey/jersey-server/
you find that there isn't 1.9
folder, but 1.9-SNAPSHOT
is. I didn't try it, but probably that should help.
It turned out that there were multiple issues with the build.sbt file. I have modified the file as follows to get it working:
libraryDependencies ++= Seq(
"javax.ws.rs" % "jsr311-api" % "1.1" % "provided, jetty",
"com.sun.jersey" % "jersey-server" % "1.8" from "http://download.java.net/maven/2/com/sun/jersey/jersey-server/1.8/jersey-server-1.8.jar",
"com.sun.jersey" % "jersey-core" % "1.8" from "http://download.java.net/maven/2/com/sun/jersey/jersey-core/1.8/jersey-core-1.8.jar",
"org.eclipse.jetty" % "jetty-webapp" % "7.3.0.v20110203" % "jetty",
"ch.qos.logback" % "logback-classic" % "0.9.26",
"org.eclipse.jetty" % "jetty-servlet" % "7.3.0.v20110203",
"asm" % "asm" % "3.1"
)
One important thing to note is that I had to remove the "provided, jetty" part from the jersey dependencies. Otherwise they would not be copied to target/webapp/WEB-INF/lib during the run of "prepare webapp".
精彩评论