英文:
package com.mongodb.client does not exist for a java console program
问题
以下是翻译好的内容:
所以这是背景故事...
我需要制作一个简单的Java控制台项目,该项目访问MongoDB数据库并对记录进行一些更改,以便另一个(规模大得多的)程序在尝试从中读取时不会发生段错误。
现在我正在尝试使我的Java控制台项目连接到MongoDB,但程序不断声明我尝试使用的包不存在。
com/logFileModifier/MainClass.java:3: 错误: 包com.mongodb.client不存在
import com.mongodb.client.MongoDatabase;
com/logFileModifier/MainClass.java:4: 错误: 包com.mongodb.client不存在
import com.mongodb.client.MongoIterable;
com/logFileModifier/MainClass.java:5: 错误: 包com.mongodb不存在
import com.mongodb.MongoClient;
我正在使用Java版本的Eclipse来开发这个项目,并且已经通过配置构建路径设置下载并添加了mongo-java-driver-#.jar、mongodb-driver-#.jar和mongodb-driver-core-#.jar到项目中。
但是没有成功。
此外,对于这个项目,我必须使用'javac ...'进行编译,并使用'java ...'进行运行,因为我将不得不将此项目从我的笔记本移动到真正的MongoDB所在的服务器上并在那里运行它。
对于那些可能会建议我使用Maven/Gradle的用户,我希望尽可能保持简单,因此我宁愿只获取.jar文件并将它们与项目一起移动。此外,我不能保证项目一旦在服务器上就能够访问互联网。
如果有人能够在这个问题上提供一些帮助,我将非常感激。
英文:
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.
答案1
得分: 0
你需要将JAR文件添加到类路径中。
这可以通过 -cp mongo-java-driver-#.jar,mongodb-driver-#.jar,mongodb-driver-core-#.jar 或者通过 CLASS_PATH 环境变量来实现。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论