So here is the back story …
I need to make a simple java console project that accesses a MongoDB database and makes some changes to the records within so that another (much larger) program doesn’t seg-fault when it tries to read from them.
Now I’m trying to get my java console project to connect to the MongoDB, but the program keeps stating the packages i’m trying to use don’t exist.
com/logFileModifier/MainClass.java:3: error: package com.mongodb.client does not exist import com.mongodb.client.MongoDatabase;
com/logFileModifier/MainClass.java:4: error: package com.mongodb.client does not exist import com.mongodb.client.MongoIterable;
com/logFileModifier/MainClass.java:5: error: package com.mongodb does not exist import com.mongodb.MongoClient;
I am using java version of Eclipse to work on this, and have downloaded and added mongo-java-driver-#.jar, mongodb-driver-#.jar, and mongodb-driver-core-#.jar to the project viva the Configure Build Path settings.
no luck
Also for this project I have to compile using ‘javac …’ and run using ‘java …’ since I’m going to have to move this project from my laptop to the server where the real MongoDB lives and run it there.
For the users that are going to say I should/need to use Maven/Gradle, I want to keep this as simple as possible, therefore I would rather just get the .jar files and move them with the project. Also I can’t guarantee that the project will have permissions to access the internet once its on the server.
If anyone could offer some help on this matter I would greatly appreciate it.
Advertisement
Answer
You need to add the jar files to the classpath. This can be done via -cp mongo-java-driver-#.jar,mongodb-driver-#.jar,mongodb-driver-core-#.jar or via CLASS_PATH environment.