Problems attempting to embed exist-db

孤街浪徒 提交于 2019-12-11 16:06:00

问题


I am trying to use exist-db in my application, so to test embedding it, i followed the guide specified on the eXist-db webppage http://www.exist-db.org/exist/apps/doc/deployment.xml. For the code in question itself:

import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Collection;
import org.xmldb.api.base.Database;
import org.exist.xmldb.DatabaseInstanceManager;
public class TestDB {       
    public static void main(String args[]) throws Exception {
        // initialize driver
        Class cl = Class.forName("org.exist.xmldb.DatabaseImpl");
        Database database = (Database)cl.newInstance();
        database.setProperty("create-database", "true");
        DatabaseManager.registerDatabase(database);

        // try to read collection
        Collection col = 
            DatabaseManager.getCollection("xmldb:exist:///db", "admin", "");
        String resources[] = col.listResources();
        System.out.println("Resources:");
        for (int i = 0; i < resources.length; i++) {
            System.out.println(resources[i]);
        }

        // shut down the database
        DatabaseInstanceManager manager = (DatabaseInstanceManager) 
            col.getService("DatabaseInstanceManager", "1.0"); 
        manager.shutdown();
    }
}

Code itself can be found at the bottom of the webppage i provided. This ended up getting stuck on the execution of DatabaseManager.getCollection("xmldb:exist:///db", "admin", "") with the following output https://pastebin.com/b6Tf7K1L .

The VM options i chose were -Djava.endorsed.dirs=lib/endorsed -Dexist.initdb=true -Dexist.home=. (using 2017.2.7 IntelliJ IDEA and Java 8).

This is the first time i am working with both exist-db and xml databases in general, and have can't figure out the solution. I have followed the "Embedding eXist in an Application" part of the guide in above provided link.


回答1:


So from your output you are missing some jar files from your classpath. The best way to avoid such things is likely to use Maven as your build system and use our Maven artifacts published at github.com/exist-db/mvn-repo

You probably want to start with a dependency on exist-core and possibly exist-testkit if you want to use the more convenient ExistEmbeddedServer class.

Apologies for the lack of detail, I only have my phone with me these last few days.

p.s. you can also find code examples of using Maven for your own eXist-db projects from the eXist book here - https://github.com/exist-book/book-code. They are for eXist 2.1 as the book was published then. I have also updated the code for eXist-db 4.0.0 here - https://github.com/eXist-book/book-code/tree/eXist-4.0.0.




回答2:


There are two open issues concerning the documentation article that you mentioned. The first one might be of help missing info the second gives you some background on general problems with the article more problems

From what i can see in your log you might have to rename log4j.xml to log4j2.xml. The lucene and log4j related errors suggest that there might be a problem with the writability of the provided location.

Please feel free to add more comments to the Github issues as well.




回答3:


The error is pretty obious:

java.lang.NoClassDefFoundError: org/apache/lucene/queryparser/classic/ParseException

The above error indicates that the class is not in your classpath. Most likely, you forgot to add lucene-queryparser-4.9.0.jar



来源:https://stackoverflow.com/questions/50067168/problems-attempting-to-embed-exist-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!