Question

I'm trying to use Mongo Database from within my Agent (using Jade agent framework). Trying to write something to database from Agent somehow did not succeed with NoClassDefFoundError.

The code is very simple as followings:

public class SomeAgent extends Agent {
    protected void setup(){
        addBehaviour(new OneShotBehaviour() {           
            @Override
            public void action() {
                MongoClient mc;
                try {
                    mc = new MongoClient();
                    DB db = mc.getDB("foo");
                    DBCollection collection = db.getCollection("bar");
                    DBObject dbobject = (DBObject) JSON.parse("{something:1}");
                    collection.insert(dbobject);
                } catch (UnknownHostException e) {
                    e.printStackTrace();
                }               
            }
        });
     }
} 

The error is java.lang.NoClassDefFoundError: com/mongodb/MongoClient, but I already included mongo java driver in eclipse build path. This is really strange. Could any of you know the potential cause for this? Any hint is much appreciated.

Was it helpful?

Solution

This kind of error is almost ever related with issues of classpath, you have to keep in mind that the buildpath of eclipse is not used in JADE runtime, you have to update the environment classpath or inform the library in the command that starts jade environment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top