How to properly use MongoDB-java-driver within Vaadin-7 project?


I’m struggling with some basic problems!

I’ve a Vaadin 7 project setup within Eclipse, just some very basic application for testing which is working properly.

But because I wanted to use it in combination with mongoDB I started with added the following code:

try {
MongoClient mongoClient = new MongoClient( “localhost” );
DB db = mongoClient.getDB( “projects” );

        Set<String> tables = db.getCollectionNames();
        for(String coll : tables){
        System.out.println("Looks okay!");
    } catch (UnknownHostException e) {
    } catch (MongoServerSelectionException e) {
        System.out.println("No MongoDB server running!");

[/code]Running this yields the following runtime error:

com.vaadin.server.ServiceException: java.lang.NoClassDefFoundError: com/mongodb/MongoServerSelectionException The mongodb-java-driver-2.12.0-rc0.jar is added to my classpath!

I’m puzzled why I get this error!

By the way, I tested the code above in a simple java project (within Eclipse, no Vaadin-7 project), which runs as aspected, and showing me a nice list of all the collections available!

Didn’t find any clue on the Internet on how to properly setup Vaadin-7 project with MongoDB! So, that’s why I’m turning to this forum, to help me find a possible solution to this issue!

Regards, Gerard

Hello Gerard,

I don’t think you have added the Mongo DB jar to the classpath. Please add the Driver jar to the folder WEB-INF/lib and run. If you still find an issue with this, please share the stripped down war. I will check and get back to you.

“Didn’t find any clue on the Internet on how to properly setup Vaadin-7 project with MongoDB!”

There is no specific set up required. Just add the driver jar to the class path(WEB-INF/lib in case of war) From your Vaadin Classes call appropriate Java class or method that connects to the MongoDB and gets your results. It is as simple as that.


Hoi Krishna,

You’re absolutely right, the jar was not in the project’s WEBINF/lib directory!

I added it to Properties>Java Build Path>Libraries tab but that doesn’t seem to be enough!?

After adding it to the WEBINF/lib directory, everything works, just great!

Thanks for your attention, and providing the solution to this basic issue!