0

I am working in Text Mining with articles from Medline. I have indexed all Medline2011 with MongoDB (http://www.mongodb.org/), now I can get one article with its PubMedID. I want join it with UIMA (http://uima.apache.org/), and I have created the DescriptorReader to get the article String from MongoDB (using MondoDB Driver for JAVA). I have this code (a quick example) and works:

public static void main(String[] args) throws UnknownHostException, MongoException {
    Mongo m = new Mongo("localhost", 27017);
    DB db = m.getDB(DB_NAME);
    DBCollection coll = db.getCollection(COLLECTION_NAME);

    BasicDBObject query = new BasicDBObject();      
    String pmid = "6889938";       
    query.put("_id", pmid);

    DBObject myDoc = coll.findOne(query);

    System.out.println(myDoc);  
}

But, when I try write the same code in a project with UIMA I have the next error:

When I use:

    private String getAbstractXMLFromMongoDB(String pmid) throws UnknownHostException, MongoException{      
        Mongo m = new Mongo(); // <-----ERROR
        ...
        return "something"

The error in console is:

ThreadGroup.uncaughtException()-Got Error
    java.lang.NoClassDefFoundError: com/mongodb/Mongo
...

And if I use try/catch:

    private String getAbstractXMLFromMongoDB(String pmid){      
    try {
        Mongo m = new Mongo(); // <-----ERROR
        ...
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (MongoException e) {
        e.printStackTrace();
    }
    return "something"

The error in console is:

Exception in thread "Thread-5" java.lang.NoClassDefFoundError: com/mongodb/MongoException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
...

I have tried (in the Example code) access to MongoDB with 100 threads at once and works... I do not know and do not undertands what is happening...

Any suggestions?

thx.

1 Answer 1

2

Provide the mongo libs to your classpath and the error should be gone.

Your try/catch approach would work, if you remove the MongoException (this one isn't known by your classpath, jars missing) and replace it with a generic Exception

If you are developing in eclipse just add the mongo jars to your buildpath. I don't know UIMA but that shouldn't matter

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

5 Comments

Thanks! I have changed the exception and I have the same problem. I have the mongo driver (*.jar) within the project. When I write "M" and press Control + SPACE, Eclipse detecs Mongo class. I have defined the path like in the Example code, and mongo jar is in the project.
As I mentioned I don't know UIMA really, are you executing the not working project in your eclipse IDE or do you export/package the project?
Asrijaal do not think in UIMA. I use API UIMA pipeline with several projects and work perfect. I can get Text to TextMining from several ways, and I want add a new way, a new class to access to mongo and get Text (like the example code), but I have this error...
Ok Alex :) But do execute your code within eclipse or do you package it and then execute it? If it is the second case, then the mongo jars aren't exported by eclipse.
OK! OK! Thank you Asrijaalfor inist in a path problem, because I thought in a thread problem. I had added my jar in the project, but not in the Main File Configuration. Now it works perefct!!! I am sorry if you have lost your time, and thank you very much again! ;)

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.