在仅Java项目中将MongoDB添加到SBT [英] Adding MongoDB to SBT in a Java only project

查看:94
本文介绍了在仅Java项目中将MongoDB添加到SBT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Play!我正在经历的框架和项目使用sbt作为其构建工具(不是Maven).我一直在尝试将MongoDB添加为build.sbt的依赖项,但到目前为止还没有成功.

I'm currently learning the Play! framework and the project that I'm going through uses sbt as its build tool (not Maven). I've been trying to add MongoDB as a dependency to build.sbt, but haven't been successful thus far.

有什么我错过的东西吗?顺便说一句,为什么我不需要将JUnit列为依赖项?

Is there something that I've missed out? Btw, why don't I need to list JUnit as a dependency?

build.sbt文件:

name := "warehouse"
version := "1.0-SNAPSHOT"
autoScalaLibrary := false

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache
)

libraryDependencies += "org.mongodb" % "mongodb-java-driver" % "3.2.0"

play.Project.playJavaSettings

还将此添加到application.conf(链接):

Also added this to application.conf (link):

# The mongo module
module.mongo=${play.path}/modules/mongo

# mongodb connection details
mongo.host=localhost
mongo.port=27017
mongo.database=play

下面是在终端中执行play compile命令时得到的编译时错误消息:

The below is the compile-time error message that I get when executing the play compile command in the terminal:

[info] Resolving org.mongodb#mongodb-java-driver;3.2.0 ...
[warn]  module not found: org.mongodb#mongodb-java-driver;3.2.0
[warn] ==== local: tried
[warn]   ~/Developer/Play/play-2.2.6/repository/local/org.mongodb/mongodb-java-driver/3.2.0/ivys/ivy.xml
[warn] ==== Maven2 Local: tried
[warn]   file:~/.m2/repository/org/mongodb/mongodb-java-driver/3.2.0/mongodb-java-driver-3.2.0.pom
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/org/mongodb/mongodb-java-driver/3.2.0/mongodb-java-driver-3.2.0.pom
[warn] ==== Typesafe Releases Repository: tried
[warn]   http://repo.typesafe.com/typesafe/releases/org/mongodb/mongodb-java-driver/3.2.0/mongodb-java-driver-3.2.0.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: org.mongodb#mongodb-java-driver;3.2.0: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
sbt.ResolveException: unresolved dependency: org.mongodb#mongodb-java-driver;3.2.0: not found
.
.
.
[error] (*:update) sbt.ResolveException: unresolved dependency: org.mongodb#mongodb-java-driver;3.2.0: not found

推荐答案

您遇到的问题是您的项目无法解决我以前遇到的依赖项.在回答您的问题之前,我想先介绍一下有关依赖关系解决过程的一些信息.

The problem you met is that your project can not resolve the dependency which I have met ever before. Before answering your question, I want to talk something about dependency resolving process as follows.

当您的项目需要解决依赖关系时,它将尝试在某些存储库中查找依赖关系.依次访问的存储库如下

When your project needs to resolve dependency, it will try to find the dependency in some repositories. The repository accessed sequencely is as following

首先,它进入您项目的存储库,就像您的项目一样,其目录为〜/Developer/Play/play-2.2.6/repository/.

Firstly, it steps into the repository of your project, as for your project, whose directory is ~/Developer/Play/play-2.2.6/repository/ .

如果未找到,将搜索目录为〜/.m2/repository/

If not found, the maven repository will be searched whose directory is ~/.m2/repository/

如果也没有找到依赖关系,它将访问Internet上的存储库,例如 http://repo1.maven.org/maven2 ,然后将其下载到本地.

If dependency is also not found, it will access the repository on the internet, such as http://repo1.maven.org/maven2, then download it to the local.

也许您的网络不支持您访问 http://repo1.maven.org/maven2,我认为这就是原因.

Maybe your network does not support that your access to http://repo1.maven.org/maven2, which I think it's the reason.

您可以通过执行以下操作来解决此问题:

You can solve this problem by doing the following things:

1)下载jar文件

1) download the jar file, http://central.maven.org/maven2/org/mongodb/mongo-java-driver/3.2.0/mongo-java-driver-3.2.0.jar

2)使用以下命令将其发布到本地Maven存储库中

2) publish it the the local maven repository using the following command

mvn install:install-file -Dfile=~/mongo-java-driver-3.2.0.jar -DgroupId=org.mongodb -DartifactId=mongo-java-driver -Dversion=3.2.0 -Dpackaging=jar

请注意

如果将驱动程序下载到目录〜/",则

If you download the driver into directory "~/", then

-Dfile =〜/mongo-java-driver-3.2.0.jar

-Dfile=~/mongo-java-driver-3.2.0.jar

如果尚未安装mvn,则只需安装它. 然后,重新打开您的项目.

If you have not installed mvn, just install it. Then, reopen your project.

祝你好运

这篇关于在仅Java项目中将MongoDB添加到SBT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆