java - 尝试嵌入exist-db时出现问题

标签 java intellij-idea 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 .

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

这是我第一次使用exist-db 和xml 数据库,并且无法找出解决方案。我已按照上面提供的链接中指南的“在应用程序中嵌入 eXist”部分进行操作。

最佳答案

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

如果您想使用更方便的 ExistEmbeddedServer 类,您可能需要从对exist-core 和可能的exist-testkit 的依赖开始。

抱歉缺少详细信息,最近几天我只带着手机。

附:您还可以从 eXist 书中找到将 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 .

关于java - 尝试嵌入exist-db时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50067168/

相关文章:

java - fragment 中的 Recyclerview,跳过未附加适配器的布局

intellij-idea - Perl 6 有 Intellij 插件吗?

xml - eXist 数据库和 XQuery : xml-root with attribute leads to no results

xml - 如何公开大量 XML 文档 (~2M) 以供离线查询 (xpath)?

Java - System.currentTimeMillis();不退差价

java - 如何从 gmail 内容提供者获取内容

Java -> Kotlin。数据类转换模式

java - 无法导入已下载到 .m2 的依赖项

java - IDEA 10.0.3 在重构时用完全限定名替换声明

variable-assignment - XSLTforms 或 betterForm 是否支持变量 (var)?