问题
I'm really new in Java and also MongoDB world. I would like to use MongoDB and Java. I have downloaded MongoDB driver for java. It is a jar file, my question is how can I use this Jar file. I've used this command but I got an error:
java -jar mongo-java-driver-2.9.3-javadoc.jar
and the error:
no main manifest attribute, in mongo-java-driver-2.9.3-javadoc.jar
could you please help me to solve the problem?
回答1:
First, that is not the correct jar. The jar you are referencing above contains the javadocs.
The driver jar is: mongo-java-driver-2.9.3.jar
.
Secondly, you need to add the jar to your project's classpath in order to use it. These are not executable jars. Take a look at the getting started docs here:
http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-java-driver/#getting-started-with-java-driver
There is no "installing" the driver. You just add it as a dependency in your project and you use it in your code. You do have to install the database itself. The installation packages for the database are available here: http://www.mongodb.org/downloads
回答2:
Some jar files include an entry point and thus can be run by themselves, using a command like the one you tried.
Other jar files do not include an entry point; they are just libraries to be used by other Java classes. The MongoDB Java driver is like this. It's not designed to be used by itself.
If you are new to Java, you should probably spend some time learning Java before trying to use the Mongo Java driver. You might try http://docs.oracle.com/javase/tutorial/. You should probably at least get though the "Language Basics" section before trying to use MongoDB with Java.
If you want to use MongoDB by itself, you can use it with the Mongo shell.
回答3:
This is how to use the 3.x monogo java driver. download the bson, monogodb driver core and mongodb driver.
add these jar files to CLASSPATH.
Or
Download the single file
来源:https://stackoverflow.com/questions/17217129/installing-mongodb-java-driver