我正在尝试设置与 MongoDB 的测试连接。我在 Eclipse 中,使用 Maven 构建。我的 pom 文件如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br-uml-manager</groupId>
<artifactId>br-uml-manager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>2.3.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<showDeprecation>true</showDeprecation>
</configuration>
<id>compileId</id>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.6.0-01</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-java-driver</artifactId>
<version>3.7.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
我已经添加了依赖项。这是我的代码:
package com.uml;
import com.mongodb.*;
public class TestMain {
public static void main(String[] args) {
System.out.println("Hello world");
MongoClient mongoClient = new MongoClient("localhost", 27017);
}
}
我已经尝试将依赖部分中的 mongodb 版本更改为 3.7。我使用的是 Java SE 1.8,这些是构建路径的一些设置:
老实说,我认为原因与我在导入 PlantUML 库“net.sourceforge.plantuml.SourceStringReader;”时遇到的另一个问题有关。
但我不确定那个问题到底是什么......
答案 0 :(得分:0)
我解决了这个问题——问题是我在插件下输入了 MondoDB 依赖