scala - 尝试使用 Scalatra 编译项目但失败

标签 scala sbt scalatra

我正在使用 Scalatra 启动一个新项目,当尝试构建流程时,编译器显示:

[info] Compiling 13 Scala sources to /home/mauricio/projects/scala/id2-search-proxy/target/scala-2.11/classes...
[error] missing or invalid dependency detected while loading class file 'ScalatraServlet.class'.
[error] Could not access term servlet in package javax,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'ScalatraServlet.class' was compiled against an incompatible version of javax.
[error] missing or invalid dependency detected while loading class file 'ScalatraServlet.class'.
[error] Could not access type HttpServlet in value javax.http,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'ScalatraServlet.class' was compiled against an incompatible version of javax.http.
[error] missing or invalid dependency detected while loading class file 'DynamicScope.class'.
[error] Could not access term servlet in package javax,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'DynamicScope.class' was compiled against an incompatible version of javax.
[error] missing or invalid dependency detected while loading class file 'RequestResponseScope.class'.
[error] Could not access term servlet in package javax,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'RequestResponseScope.class' was compiled against an incompatible version of javax.
[error] missing or invalid dependency detected while loading class file 'ScalatraContext.class'.
[error] Could not access term servlet in package javax,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'ScalatraContext.class' was compiled against an incompatible version of javax.
[error] missing or invalid dependency detected while loading class file 'DynamicScope.class'.
[error] Could not access type HttpServletResponse in value javax.http,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'DynamicScope.class' was compiled against an incompatible version of javax.http.
[error] missing or invalid dependency detected while loading class file 'DynamicScope.class'.
[error] Could not access type HttpServletRequest in value javax.http,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'DynamicScope.class' was compiled against an incompatible version of javax.http.
[error] missing or invalid dependency detected while loading class file 'SessionSupport.class'.
[error] Could not access term servlet in package javax,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'SessionSupport.class' was compiled against an incompatible version of javax.
[error] missing or invalid dependency detected while loading class file 'SessionSupport.class'.
[error] Could not access type HttpSession in value javax.http,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'SessionSupport.class' was compiled against an incompatible version of javax.http.
[error] missing or invalid dependency detected while loading class file 'ServletApiImplicits.class'.
[error] Could not access term servlet in package javax,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'ServletApiImplicits.class' was compiled against an incompatible version of javax.
[error] missing or invalid dependency detected while loading class file 'Route.class'.
[error] Could not access term servlet in package javax,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'Route.class' was compiled against an incompatible version of javax.
[error] missing or invalid dependency detected while loading class file 'ScalatraServlet.class'.
[error] Could not access type ServletConfig in value javax.servlet,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'ScalatraServlet.class' was compiled against an incompatible version of javax.servlet.
[error] missing or invalid dependency detected while loading class file 'ServletApiImplicits.class'.
[error] Could not access type ServletContext in value javax.servlet,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'ServletApiImplicits.class' was compiled against an incompatible version of javax.servlet.
[error] missing or invalid dependency detected while loading class file 'ServletApiImplicits.class'.
[error] Could not access type HttpSession in value javax.http,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'ServletApiImplicits.class' was compiled against an incompatible version of javax.http.
[error] missing or invalid dependency detected while loading class file 'ServletApiImplicits.class'.
[error] Could not access type HttpServletResponse in value javax.http,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'ServletApiImplicits.class' was compiled against an incompatible version of javax.http.
[error] missing or invalid dependency detected while loading class file 'ServletApiImplicits.class'.
[error] Could not access type HttpServletRequest in value javax.http,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'ServletApiImplicits.class' was compiled against an incompatible version of javax.http.
[error] 16 errors found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 6 s, completed 23/09/2015 13:03:32

我在 scalatra 源代码或我这里的文件中找不到这些损坏的引用,所有导入看起来都是正确的。知道这里发生了什么吗?

我的SBT文件是这样的:

name := "id2-search-proxy"

version := "1.0"

scalaVersion := "2.11.7"

lazy val versions = new {
  val scalatra = "2.4.0-RC2-2"
  val specs2 = "3.6.4-20150916230958-8339115"
}

resolvers ++= Seq(
  Resolver.sonatypeRepo("releases"),
  "Twitter Maven" at "https://maven.twttr.com"
)

libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.1.3"

libraryDependencies += "com.ning" % "async-http-client" % "1.9.31"

libraryDependencies += "commons-io" % "commons-io" % "2.4"

libraryDependencies += "io.argonaut" %% "argonaut" % "6.1-M4"

libraryDependencies += "oauth.signpost" % "signpost-core" % "1.2.1.2"

libraryDependencies += "oauth.signpost" % "signpost-commonshttp4" % "1.2.1.2"

libraryDependencies += "org.mockito" % "mockito-core" % "1.10.19" % Test

libraryDependencies += "org.specs2" %% "specs2-core" % versions.specs2 % Test

libraryDependencies += "org.specs2" %% "specs2-mock" % versions.specs2 % Test

libraryDependencies += "org.scalatra" %% "scalatra" % versions.scalatra

libraryDependencies += "org.scalatra" %% "scalatra-specs2" % versions.scalatra % Test

resolvers += "twitter-repo" at "http://maven.twttr.com/"

resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"

scalacOptions in Test ++= Seq("-Yrangepos", "-Ylog-classpath")

最佳答案

由于 servlet-api 设置为提供它将在 Idea 上加载,但在编译期间不可用,直接依赖它修复了问题:

libraryDependencies += "javax.servlet" % "javax.servlet-api" % "3.1.0"

关于scala - 尝试使用 Scalatra 编译项目但失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32745566/

相关文章:

scala - 如何在 Windows 中安装 conscript

scala - 具有 swagger 支持的 scalatra 应用程序的 spec2 测试失败

scala - fs2.Stream[IO, Something] 不返回 take(1)

excel - 由于依赖问题,无法使用spark-excel导出数据框

scala - 如何执行仅匹配正则表达式的测试?

java - 使用 settings.xml 解决 sbt 的 java Artifact

scala - 如何在 Scala 中访问类的类型参数

scala - 如何使用akka-http设计一个rest api以便于测试?

scala - 需要以下 scala 片段的简单英文翻译

scala - 如何捕获任何 scalatra 操作中的所有错误?