Issue
I am trying to setup a test connection to MongoDB. I am in Eclipse, using a Maven build. My pom file is below:
<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>
I've added the dependencies. And this is my code:
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);
}
}
I've tried changing the version of mongodb in the dependency part to 3.7. I'm using Java SE 1.8, and these are some settings for build path:
I honestly think the cause is related to another issue I was getting, when I was importing a PlantUML library "net.sourceforge.plantuml.SourceStringReader;"
But I'm not sure what exactly that issue is...
Solution
I fixed the issue -- the problem was that I was I had entered the MondoDB dependencies under plugin
Answered By - anon comp