当我尝试编译项目时,我从sbt得到以下错误:
[error] /opt/devel/src/sophia/src/main/scala/JettyLauncher.scala:3: object eclipse is not a member of package org
[error] import org.eclipse.jetty.server.nio.SelectChannelConnector
[error] ^
[error] /opt/devel/src/sophia/src/main/scala/JettyLauncher.scala:4: object eclipse is not a member of package org
[error] import org.eclipse.jetty.server.{ Server }
[error] ^
[error] /opt/devel/src/sophia/src/main/scala/JettyLauncher.scala:5: object eclipse is not a member of package org
[error] import org.eclipse.jetty.server.handler.ContextHandlerCollection
[error] ^
[error] /opt/devel/src/sophia/src/main/scala/JettyLauncher.scala:6: object eclipse is not a member of package org
[error] import org.eclipse.jetty.webapp.WebAppContext
[error] ^
[error] /opt/devel/src/sophia/src/main/scala/JettyLauncher.scala:7: object eclipse is not a member of package org
[error] import org.eclipse.jetty.servlet.{ DefaultServlet, ServletContextHandler, ServletHolder }
[error] ^
[warn] /opt/devel/src/sophia/src/main/scala/JettyLauncher.scala:14: This catches all Throwables. If this is really intended, use `case _ : Throwable` to clear this warning.
[warn] case _ => 8080
[warn] ^
[error] /opt/devel/src/sophia/src/main/scala/JettyLauncher.scala:18: not found: type Server
[error] val server: Server = new Server
[error] ^
[error] /opt/devel/src/sophia/src/main/scala/JettyLauncher.scala:18: not found: type Server
[error] val server: Server = new Server
[error] ^
[error] /opt/devel/src/sophia/src/main/scala/JettyLauncher.scala:25: not found: type SelectChannelConnector
[error] val connector = new SelectChannelConnector
[error] ^
[error] /opt/devel/src/sophia/src/main/scala/JettyLauncher.scala:31: not found: type WebAppContext
[error] val webApp = new WebAppContext
[error] ^
[error] /opt/devel/src/sophia/src/main/scala/MongoDBServlet.scala:3: object Akka2Support is not a member of package org.scalatra.akka
[error] import org.scalatra.akka.Akka2Support
[error] ^
[error] /opt/devel/src/sophia/src/main/scala/MongoDBServlet.scala:8: not found: type Akka2Support
[error] class MongoDBServlet extends ScalatraServlet with Akka2Support {
[error] ^
[error] /opt/devel/src/sophia/src/main/scala/MongoDBServlet.scala:13: not found: value ExecutionContext
[error] ExecutionContext.fromExecutorService(Executors.newCachedThreadPool())
[error] ^
[error] /opt/devel/src/sophia/src/main/scala/MongoDBServlet.scala:23: not found: value Future
[error] Future {
[error] ^
[warn] one warning found
[error] 13 errors found
以下是我的build.sbt
文件的内容:
scalaVersion := "2.10.4"
mainClass := Some("JettyLauncher")
seq(webSettings :_*)
port in container.Configuration := 8080
seq(assemblySettings: _*)
libraryDependencies += "org.mongodb" %% "casbah-core" % "2.7.3"
libraryDependencies += "org.scalatra" %% "scalatra" % "2.2.0-RC3" cross CrossVersion.binary
libraryDependencies += "org.scalatra" %% "scalatra-akka" % "2.2.0-RC3"
libraryDependencies += "org.scalatra" %% "scalatra-specs2" % "2.2.0" % "test"
libraryDependencies += "org.mortbay.jetty" % "servlet-api" % "3.0.20100224" % "provided"
libraryDependencies += "org.eclipse.jetty" % "jetty-server" % "9.0.0.M5" % "container"
libraryDependencies += "org.eclipse.jetty" % "jetty-util" % "9.0.0.M5" % "container"
libraryDependencies += "org.eclipse.jetty" % "jetty-webapp" % "9.0.0.M5" % "container"
resolvers ++= Seq(
"Sonatype releases" at "http://oss.sonatype.org/content/repositories/releases/",
"Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/",
"Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/",
"Akka Repo" at "http://akka.io/repository/",
"Web plugin repo" at "http://siasia.github.com/maven2"
)
以下是我的plugins.sbt
文件的内容:
addSbtPlugin("com.earldouglas" %% "xsbt-web-plugin" % "0.9.0")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.7.2")
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
我生成了一个eclipse项目,因为我可以查看.classpath
文件。果然,我发现其中一些类不在类路径中......
如何将这些文件放入类路径?
感谢您的帮助!
编辑:我决定在~/.ivy2/cache/org.eclipse.jetty.
中挖掘我的JARS。我决定首先查找SelectChannelConnector
类(我从sbt获得的第一个错误)。在org.eclipse.jetty
目录中有一个jetty-server
目录,所以我去了那里。现在在jetty-server
目录中有一堆常春藤xml文件和两个目录,一个用于jar,另一个用于srcs。然后我进入了jars目录。在jars目录中有4个罐子:
jetty-server-8.0.0.M3.jar jetty-server-9.0.0.M5.jar
jetty-server-8.1.8.v20121106.jar jetty-server-9.1.0.v20131115.jar
8.*
版本归因于我的build.sbt.
中的版本更改使用了命令jar -tf [JAR-FILE]| grep nio' I found that the
SelectChannelConnector.class file exists in the
8. jars and not the
9。 jars. Note that my
build.sbt specifies the
9.0.0.M5` jar。
我的第一个想法是,sbt只关注这些9.*
罐子,如果我删除8.*
罐子并重新加载我的项目,那么正确的类将被下载到{{1罐子。事实并非如此。
我不确定此时还有什么可以尝试的。我可以尝试手动添加这些罐子,但这听起来不错。
感谢您的帮助!
答案 0 :(得分:2)
我认为这已经解决了here
基本上,您将jetty-webapp
标记为container
和provided
"org.eclipse.jetty" % "jetty-webapp" % "8.1.7.v20120910" % "container;provided"
希望它有所帮助。
答案 1 :(得分:0)
您将码头标记为“已提供”。这意味着jetty在运行时不可用。