java.lang.NoClassDefFoundError when using MongoDB driver

前端 未结 2 455
迷失自我
迷失自我 2020-12-03 23:08

I am trying to connect to a MongoDB database hosted on mlab using the Java driver on a servlet.

import org.bson.Document; 
import com.mongodb.MongoClient;
im         


        
2条回答
  •  独厮守ぢ
    2020-12-03 23:31

    You have java.lang.NoClassDefFoundError - that means your class is missed during runtime (not during build/compile time). So you should open your "Run Configurations" dialog for the project (project context menu -> "Run As" -> "Run Configurations...") and make sure you have bson-xxx.jar, mongodb-driver-xxx.jar, and mongodb-driver-core-xxx.jar somehow listed in Classpath tab. And yes, like Xavier Bouclet said - if you run it under application server - this jars should be added to your server's classpath.

提交回复
热议问题