5

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?

3 Answers 3

9

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

Sign up to request clarification or add additional context in comments.

3 Comments

@TangoStar - You can't run these jars like you are trying to above. The are not executable. You have to add them to your classpath and use them in your code. Did you read the link I supplied? I have also edited my answer for clarity.
just out of curiosity, and this is a good answer, but how do you know that's the right driver? why isn't the driver downloadable from the mongo database?
@Thufir - The drivers are provided on the Mongo site: docs.mongodb.org/ecosystem/drivers. I assume they are not included with the download because there are so many. You can go to the driver site above and get the driver that matches your version of mongodb.
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.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.