0
votes

I'm trying to get a simple ScalatraServlet running.

When I compile I can see that it fails to import any of my Scalatra componenents. Strangely enough, it's trying to compile to a directory called scala-2.10/classes, even though I'm using Scala 2.11.

What's going wrong with my project?

sal@gruntyman:~/workspace/funproxy$ sbt compile
[info] Loading project definition from /home/sal/workspace/funproxy/project
[info] Set current project to funproxy (in build file:/home/sal/workspace/funproxy/)
[info] Updating {file:/home/sal/workspace/funproxy/}funproxy...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 3 Scala sources to /home/sal/workspace/funproxy/target/scala-2.10/classes...
[error] /home/sal/workspace/funproxy/src/main/scala/ProxyServlet.scala:5: object scalatra is not a member of package org
[error] import org.scalatra.ScalatraServlet
[error]            ^
[error] /home/sal/workspace/funproxy/src/main/scala/ProxyServlet.scala:7: not found: type ScalatraServlet
[error] class ProxyServlet extends ScalatraServlet with ScalateSupport {
[error]                            ^
[error] /home/sal/workspace/funproxy/src/main/scala/ProxyServlet.scala:7: not found: type ScalateSupport
[error] class ProxyServlet extends ScalatraServlet with ScalateSupport {
[error]                                                 ^
[error] /home/sal/workspace/funproxy/src/main/scala/ProxyServlet.scala:11: not found: value get
[error]   get("/") {
[error]   ^
[error] four errors found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 0 s, completed 31-Jan-2016 14:23:46
sal@gruntyman:~/workspace/funproxy$ sbt --version
sbt launcher version 0.13.7

This is my SBT config:

name := "funproxy"

version := "0.0.1"

scalaVersion := "2.11.7"

lazy val scalatraVersion = "2.3.1"
libraryDependencies += "javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided"
libraryDependencies += "org.slf4j" % "slf4j-simple" % "1.7.14"
libraryDependencies += "junit" % "junit" % "4.10" % "test"
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.5" % "test"
libraryDependencies += "org.scalatra" %% "scalatra" % scalatraVersion
libraryDependencies += "org.scalatra" %% "scalatra-scalate" % scalatraVersion
libraryDependencies += "org.scalatra" %% "scalatra-specs2" % scalatraVersion % "test"
libraryDependencies += "org.eclipse.jetty" % "jetty-webapp" % "9.2.10.v20150310" % "runtime"
//libraryDependencies +=  "ch.qos.logback"    %  "logback-classic"   % "1.1.3"            % "runtime"
//libraryDependencies += "net.databinder.dispatch" %% "dispatch-core" % "0.11.2"

scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
1
What is "my SBT config". Is that a file named build.sbt in your project's root folder? Because if not, sbt will not pick it up. The scalatra-not-found error hints at this, too. You can easily find out by running sbt without arguments, and on the sbt console execute show name, show version, show scalaVersion.0__
OK, it was called build.sbt but it was in project/ - moved now, and that seemed to fix it. Thanks!Salim Fadhley

1 Answers

2
votes

sbt finds build files only if they are in simple .sbt format within the project's root directory, or if they are in full .scala format in the sub-directory project. If you place an .sbt file inside the project sub-directory, that will be for the meta-project, e.g. containing plugin definitions.