简体   繁体   English

java 控制台程序不存在包 com.mongodb.client

[英]package com.mongodb.client does not exist for a java console program

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.我需要创建一个简单的 java 控制台项目来访问 MongoDB 数据库并对其中的记录进行一些更改,以便另一个(更大的)程序在尝试读取它们时不会出现段错误。

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.现在我试图让我的 java 控制台项目连接到 MongoDB,但程序一直声明我尝试使用的包不存在。

com/logFileModifier/MainClass.java:3: error: package com.mongodb.client does not exist import com.mongodb.client.MongoDatabase; com/logFileModifier/MainClass.java:3: 错误:包 com.mongodb.client 不存在 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:4: 错误:包 com.mongodb.client 不存在 import com.mongodb.client.MongoIterable;

com/logFileModifier/MainClass.java:5: error: package com.mongodb does not exist import com.mongodb.MongoClient; com/logFileModifier/MainClass.java:5: 错误:com.mongodb 包不存在 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.我正在使用 Eclipse 的 Java 版本来解决这个问题,并且已经下载并添加了 mongo-java-driver-#.jar、mongodb-driver-#.jar 和 mongodb-driver-core-#.jar 到项目 viva the配置构建路径设置。

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.同样对于这个项目,我必须使用“javac ...”进行编译并使用“java ...”运行,因为我必须将这个项目从我的笔记本电脑移动到真正的 MongoDB 所在的服务器并在那里运行它.

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.对于那些会说我应该/需要使用 Maven/Gradle 的用户,我希望尽可能简单,因此我宁愿只获取 .jar 文件并将它们与项目一起移动。 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.如果有人能在这件事上提供一些帮助,我将不胜感激。

You need to add the jar files to the classpath.您需要将 jar 文件添加到类路径中。 This can be done via -cp mongo-java-driver-#.jar,mongodb-driver-#.jar,mongodb-driver-core-#.jar or via CLASS_PATH environment.这可以通过 -cp mongo-java-driver-#.jar,mongodb-driver-#.jar,mongodb-driver-core-#.jar 或通过 CLASS_PATH 环境来完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM