Maven项目中的Scala jar:未能找到org.mongodb:casbah_2.12:jar:3.1.1

时间:2017-04-09 18:07:08

标签: java mongodb scala maven sbt

斯帕拉和新手在这里。我创建了一个使用casbah

的Scala sbt项目
libraryDependencies += "org.mongodb" %% "casbah" % "3.1.1"

查询mongodb并将结果作为地图返回。我想在我的Java maven项目中使用这段代码来操作我从查询数据库中得到的结果。

我将此添加到我的build.sbt文件中:

publishMavenStyle := true

publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath + "/.m2/repository")))

在我的.m2本地仓库中安装一个jar文件。这是我做sbt publish时的输出:

> publish
[info] Packaging /Users/miguelvelez/Documents/Programming/Scala/Projects/mongo/target/scala-2.12/mongo_2.12-0.1.0-SNAPSHOT-sources.jar ...
[info] Done packaging.
[info] Main Scala API documentation to /Users/miguelvelez/Documents/Programming/Scala/Projects/mongo/target/scala-2.12/api...
[info] Packaging /Users/miguelvelez/Documents/Programming/Scala/Projects/mongo/target/scala-2.12/mongo_2.12-0.1.0-SNAPSHOT.jar ...
[info] Done packaging.
[info] Wrote /Users/miguelvelez/Documents/Programming/Scala/Projects/mongo/target/scala-2.12/mongo_2.12-0.1.0-SNAPSHOT.pom
[info] :: delivering :: edu.cmu.cs.mvelezce#mongo_2.12;0.1.0-SNAPSHOT :: 0.1.0-SNAPSHOT :: integration :: Sun Apr 09 13:58:46 EDT 2017
[info]  delivering ivy file to /Users/miguelvelez/Documents/Programming/Scala/Projects/mongo/target/scala-2.12/ivy-0.1.0-SNAPSHOT.xml
model contains 9 documentable templates
[info] Main Scala API documentation successful.
[info] Packaging /Users/miguelvelez/Documents/Programming/Scala/Projects/mongo/target/scala-2.12/mongo_2.12-0.1.0-SNAPSHOT-javadoc.jar ...
[info] Done packaging.
[info]  published mongo_2.12 to /Users/miguelvelez/.m2/repository/edu/cmu/cs/mvelezce/mongo_2.12/0.1.0-SNAPSHOT/mongo_2.12-0.1.0-SNAPSHOT.pom
[info]  published mongo_2.12 to /Users/miguelvelez/.m2/repository/edu/cmu/cs/mvelezce/mongo_2.12/0.1.0-SNAPSHOT/mongo_2.12-0.1.0-SNAPSHOT.jar
[info]  published mongo_2.12 to /Users/miguelvelez/.m2/repository/edu/cmu/cs/mvelezce/mongo_2.12/0.1.0-SNAPSHOT/mongo_2.12-0.1.0-SNAPSHOT-sources.jar
[info]  published mongo_2.12 to /Users/miguelvelez/.m2/repository/edu/cmu/cs/mvelezce/mongo_2.12/0.1.0-SNAPSHOT/mongo_2.12-0.1.0-SNAPSHOT-javadoc.jar
[success] Total time: 3 s, completed Apr 9, 2017 1:58:49 PM

然后我在我的pom文件中导入了这个依赖项:

<dependency>
    <groupId>edu.cmu.cs.mvelezce</groupId>
    <artifactId>mongo_2.12</artifactId>
    <version>0.1.0-SNAPSHOT</version>
</dependency>

当我运行mvn compile时,我收到以下错误:

[ERROR] Failed to execute goal on project performance-mapper: Could not resolve dependencies for project edu.cmu.cs.mvelezce:performance-mapper:jar:0.1.0-SNAPSHOT: Failure to find org.mongodb:casbah_2.12:jar:3.1.1 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

我知道casbah有几个模块,我只能导入一些而不是全部。但是,按照Casbah中的文档,我添加了enterie库。我也看了Maven Central,这个版本的casbah没有罐子;只有独立的模块。我在我的pom中添加了一些这些模块,但我仍然遇到与上面相同的错误。 Maven正在寻找完整的jar文件。

有没有办法解决这个问题?我以为我只能在build.sbt文件中添加我需要的Scala依赖项,但是当我这样做时,我遇到了编译错误。有没有人提出建议?

谢谢!

1 个答案:

答案 0 :(得分:0)

您需要确保Casbah依赖项在项目中的类型为pom。例如,在你的pom.xml中添加以下内容:

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>casbah_2.11</artifactId>
    <version>3.1.1</version>
    <type>pom</type>
</dependency>