Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scala build with SBT cannot import java classes?

Tags:

scala

sbt

I got some strange problems when using sbt to build a simple Scala class. The code is simply enough which I copied from internet to start a jetty server:

object JettyEmbedded {

  def main(args: Array[String]) {
    val server = new org.eclipse.jetty.server.Server(9080)
    val context= new org.eclipse.jetty.webapp.WebAppContext()

    context.setServer(server)
    context.setContextPath("/");
    context.setWar("src/main/webapp")
    server.setHandler(context);

    try {
      server.start()
      server.join()
    } catch {
      case e: Exception => {
        e.printStackTrace()
        System.exit(1)
      }
    }
  }
}

to compile with SBT and scala 2.9.2, i got the following error:

[error] /src/main/scala/JettyEmbedded.scala:4: object eclipse is not a member of package org
[error] val server = new org.eclipse.jetty.server.Server(9080)

I can see in build.sbt, i have dependencies like:

"org.eclipse.jetty" % "jetty-webapp" % "8.1.7.v20120910" % "container",
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar"))

If I just remove this offending file and run the Jetty server with container:start from sbt, it runs no problem!

like image 934
Wudong Avatar asked Oct 05 '22 14:10

Wudong


1 Answers

Change this line:

"org.eclipse.jetty" % "jetty-webapp" % "8.1.7.v20120910" % "container",

to:

"org.eclipse.jetty" % "jetty-webapp" % "8.1.7.v20120910" % "container;provided",

solved the problem.

sbt don't put "container" class into the compilation classpath, while in Eclipse it don't care.

like image 69
Wudong Avatar answered Oct 10 '22 11:10

Wudong