尝试嵌入的问题exists-db

时间:2018-04-27 17:03:27

标签: java intellij-idea exist-db

我正在尝试在我的应用程序中使用exists-db,因此为了测试嵌入它,我遵循了eXist-db webppage http://www.exist-db.org/exist/apps/doc/deployment.xml上指定的指南。 对于有问题的代码本身:

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();
    }
}

代码本身可以在我提供的webppage的底部找到。 这最终导致DatabaseManager.getCollection("xmldb:exist:///db", "admin", "")执行时遇到以下输出https://pastebin.com/b6Tf7K1L

我选择的VM选项是-Djava.endorsed.dirs=lib/endorsed -Dexist.initdb=true -Dexist.home=.(使用2017.2.7 IntelliJ IDEA和Java 8)。

这是我第一次使用exists-db和xml数据库,并且无法找到解决方案。我已按照&#34;在应用程序中嵌入eXist&#34;以上指南的一部分提供了链接。

3 个答案:

答案 0 :(得分:1)

因此,从您的输出中,您缺少类路径中的一些jar文件。避免此类事情的最佳方法是使用Maven作为构建系统并使用我们在github.com/exist-db/mvn-repo上发布的Maven工件

如果您想使用更方便的ExistEmbeddedServer类,您可能希望从依赖于exists-core和可能存在的testkit开始。

对于缺乏细节的道歉,过去几天我只收到了我的电话。

P.S。您还可以在这里找到使用Maven为您自己的eXist-db项目编写的代码示例 - https://github.com/exist-book/book-code。当这本书出版时,它们适用于eXist 2.1。我还在这里更新了eXist-db 4.0.0的代码 - https://github.com/eXist-book/book-code/tree/eXist-4.0.0

答案 1 :(得分:0)

您提到的文档文章有两个未解决的问题。第一个可能会有所帮助missing info第二个可以为您提供有关文章more problems的一般问题的背景信息

根据我在日志中看到的内容,您可能需要将log4j.xml重命名为log4j2.xml。 lucene和log4j相关的错误表明可能存在所提供位置的可写性问题。

请随时为Github问题添加更多评论。

答案 2 :(得分:0)

错误非常明显:

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

上述错误表明该类不在您的类路径中。很可能,您忘了添加lucene-queryparser-4.9.0.jar