尝试嵌入 exist-db 的问题

Problems attempting to embed exist-db

我正在尝试在我的应用程序中使用 exist-db,因此为了测试嵌入它,我遵循了 eXist-db 网页 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();
    }
}

代码本身可以在我提供的网页底部找到。 这最终卡在了 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)。

这是我第一次同时使用 exist-db 和 xml 一般的数据库,并且无法找出解决方案。我遵循了上面提供的 link 指南的 "Embedding eXist in an Application" 部分。

关于您提到的文档文章,有两个未解决的问题。第一个可能会有帮助 missing info the second gives you some background on general problems with the article more problems

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

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

因此,根据您的输出,您在 class 路径中丢失了一些 jar 文件。避免此类事情的最佳方法可能是使用 Maven 作为构建系统并使用我们在 github.com/exist-db/mvn-repo

发布的 Maven 工件

如果您想使用更方便的 ExistEmbeddedServer class。

,您可能希望从对 exist-core 和可能的 exist-testkit 的依赖开始

抱歉没有提供详细信息,最近几天我只有 phone 随身携带。

p.s。您还可以从此处的 eXist 书中找到将 Maven 用于您自己的 eXist-db 项目的代码示例 - 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.

错误很明显:

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

以上错误表明 class 不在您的 class 路径中。您很可能忘记添加 lucene-queryparser-4.9.0.jar