我正在尝试在我的应用程序中使用exist-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();
}
}代码本身可以在我提供的网页底部找到。这样做的结果是在执行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和Java8)。
这是我第一次同时使用exist-db和xml数据库,并且无法找到解决方案。在上面提供的链接中,我遵循了指南的“将eXist嵌入应用程序”的部分内容。
发布于 2018-05-02 06:21:45
因此,从您的输出中,您丢失了类路径中的一些jar文件。避免这种情况的最佳方法可能是使用Maven作为您的构建系统,并使用在github.com/exist-db/mvn-repo上发布的Maven构件。
如果您想使用更方便的ExistEmbeddedServer类,您可能希望首先依赖exist-core,也可能是exist-testkit。
对于缺乏细节表示歉意,最近几天我只带了我的手机。
附注:您还可以从eXist书- https://github.com/exist-book/book-code中找到将Maven用于您自己的eXist-db项目的代码示例。他们是为eXist 2.1,因为这本书是在那时出版。我还更新了eXist-db 4.0.0这里- https://github.com/eXist-book/book-code/tree/eXist-4.0.0的代码。
发布于 2018-04-27 17:58:08
发布于 2018-05-02 09:56:15
这一错误相当严重:
java.lang.NoClassDefFoundError: org/apache/lucene/queryparser/classic/ParseException
上面的错误表示类不在类路径中。很可能,您忘记添加lucene-queryparser-4.9.0.jar了
https://stackoverflow.com/questions/50067168
复制相似问题