简体   繁体   中英

Scala + Eclipse + Casbah = object mongodb is not a member of package com

I'm using spray with casbah and salat. I get this error when I import the casbah imports,

import com.mongodb.casbah.Imports._

object mongodb is not a member of package com

However, sbt compiles successfully w/o any warning. My build.sbt looks

scalaVersion  := "2.10.3"

scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8")

resolvers ++= Seq(
  "spray repo" at "http://repo.spray.io/",
   "Sonatype releases" at "https://oss.sonatype.org/content/repositories/releases"
)

libraryDependencies ++= {
  val akkaV = "2.2.3"
  val sprayV = "1.2.0"
  Seq(
    "io.spray"            %   "spray-can"     % sprayV,
    "io.spray"            %   "spray-routing" % sprayV,
    "io.spray"            %   "spray-testkit" % sprayV  % "test",
    "com.typesafe.akka"   %%  "akka-actor"    % akkaV,
    "com.typesafe.akka"   %%  "akka-testkit"  % akkaV   % "test",
    "org.specs2"          %%  "specs2-core"   % "2.3.7" % "test",
    "org.mongodb"         %%  "casbah"        % "2.7.0-RC0",
    "com.novus"           %%  "salat"         % "1.9.5"
  )
}

Any idea on how to convince Eclipse to find the package?

使用sbteclipse插件配置eclipse项目: https : //github.com/typesafehub/sbteclipse

Salat uses Casbah 2.6.4 and has it listed as a dependency[1] so there may be an issue trying to have two different versions. Try changing it to 2.6.4 or removing it and allowing salat to implicitly declare it.

[1] https://github.com/novus/salat/blob/master/project/SalatBuild.scala#L150

我最终通过将casbah和salat依赖项添加到build.sbt,运行sbt eclipse并手动将新的.classpath文件复制到导入的eclipse项目中来编辑原始模板spray项目。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM