How to resolve ClassNotFoundException: com.mongb.connection.BufferProvider?

I am trying to write simple Java code that shows MongoDB collections on the console. I added mongodb-driver-3.0.0.jar to my classpath.

But when I try to execute the code, it gives me the following error in the database connection string:

An exception in the thread "main" java.lang.NoClassDefFoundError: com / mongodb / connection / BufferProvider at com.chintan.app.MongoDbJdbc.main (MongoDbJdbc.java:12) Called: java.lang.ClassNotFoundException: com.mongbconn BufferProvider at java.net.URLClassLoader $ 1.run (Unknown source) in java.net.URLClassLoader $ 1.run (Unknown source) in java.security.AccessController.doPrivileged (native method) in java.net.URLClassLoader.findClass (Unknown source) ) in java.lang.ClassLoader.loadClass (Unknown source) in sun.misc.Launcher $ AppClassLoader.loadClass (Unknown source) in java.lang.ClassLoader.loadClass (Unknown source) ... 1 more

The following is a snippet of code:

public static void main(String[] args) { MongoClient mongoClient = new MongoClient("localhost", 27017); //Exception @SuppressWarnings("deprecation") DB db = mongoClient.getDB("mydb"); System.out.println("Database connection successfull."); ... ... } 

What is the problem? Do I need to add another jar to the classpath or is there a problem with the version?

+14
java mongodb
source share
5 answers

On the mongo driver page here: http://mongodb.imtqy.com/mongo-java-driver/3.0/driver/getting-started/installation-guide/#mongodb-driver

You will see the following text:

Note: the following dependencies are required for the mongodb driver: bson and mongodb-driver-core

So, to do this, you need all of the following banks:

mongodb-driver-3.0.1.jar, mongodb-driver-core-3.0.1.jar, bson-3.0.1.jar

What can be downloaded here: https://oss.sonatype.org/content/repositories/releases/org/mongodb/mongodb-driver/3.0.1/ https://oss.sonatype.org/content/repositories/releases/org /mongodb/mongodb-driver-core/3.0.1/ https://oss.sonatype.org/content/repositories/releases/org/mongodb/bson/3.0.1/

+34
source share

The following java driver contains the BufferProvider class:

http://mvnrepository.com/artifact/org.mongodb/mongo-java-driver/3.0.0

+3
source share

This class is located in the mongodb-driver-core-3.0.0 jar file, which is required by mongodb-driver-3.0.0.jar . You can see the java driver dependencies in the POM file associated with this bank.
I think you need to use the dependency manager to automatically add transit dependencies of MongoDB (and other components) to your project (maven, gradle, ...).

0
source share

If you do not have a maven project, just enable mongo-java-driver-3.6.1.jar (this jar is only for Java) in your project you do not need to include other banks.

0
source share

include the mongo-java-driver-3.11.0.jar file in the class path and not in the module path.

0
source share

All Articles