I'm trying to connect to a local MongoDB instance (version 3.2). I've specified a dependency in my build.gradle like so:
dependencies { compile 'org.mongodb:mongodb-driver:3.3.0' }
I have a simple App.java file with the following code (see below). The build/compileJava steps all run well with no errors. But when I run the code, I get: "Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/MongoClient at App.main(App.java:9)
I'm new to Java. I'm not sure if I need to download the driver in addition to referencing it in the build.gradle dependency list, and if so, where to place it.
Here's my src/main/java/App.java:
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoDatabase;
public class App{
public static void main (String[] args){
System.out.println("Connecting ... ");
try {
MongoClient client = new MongoClient();
}
catch(Exception e) {
System.out.println("Failed to connect to MongoDB");
}
}
}