我对 Jackrabbit 和 Jackrabbit Oak 完全陌生。不过,我与 Alfresco 合作了很多,这是另一个符合 JCR 的开源内容存储库。
我想启动一个独立的 Jackrabbit Oak 存储库,然后通过 Java 代码连接到它。不幸的是,Oak 文档非常稀缺。
我检查了 Oak 存储库,使用它构建它,mvn clean install
然后通过以下方式运行独立服务器(内存存储库目前适合我进行测试):
$ java -jar oak-run-1.6-SNAPSHOT.jar server
Apache Jackrabbit Oak 1.6-SNAPSHOT
Starting Oak-Memory repository -> http://localhost:8080/
13:14:38.317 [main] WARN o.a.j.s.r.d.ProtectedRemoveManager - protectedhandlers-config is missing -> DIFF processing can fail for the Remove operation if the content toremove is protected!
当我打开http://localhost:8080/时,我看到一个空白页面,其中包含这样的代码,但 html / xhtml 输出作为源代码如下:
我尝试通过 Java 代码进行连接:
JcrUtils.getRepository("http://localhost:8080");
// or
JcrUtils.getRepository("http://localhost:8080/rmi");
但得到:
Connecting to http://localhost:8080
Exception in thread "main" javax.jcr.RepositoryException: Unable to access a repository with the following settings:
org.apache.jackrabbit.repository.uri: http://localhost:8080
The following RepositoryFactory classes were consulted:
org.apache.jackrabbit.oak.jcr.OakRepositoryFactory: declined
org.apache.jackrabbit.commons.JndiRepositoryFactory: declined
Perhaps the repository you are trying to access is not available at the moment.
at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:223)
at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:263)
at Main.main(Main.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
(Oak 文档不如 Jackrabbit 文档完整,但我也不确定 Jackrabbit 2 中多少内容对 Oak 仍然有效,因为它是完全重写的。)
我在邮件列表/Nabble 中发现了相同的问题,但那里提供的答案不使用远程独立存储库,而是在同一个 servlet 容器甚至应用程序中运行的本地存储库(只是最终配置了 Mongo DB / Node 存储作为远程,但这意味着需要打开 Mongo 端口)。所以应用程序自己创建了存储库,这不是我的情况(我的情况在 Oak 中也可以正常工作)。
在 Jackrabbit2(不是 Oak)中,我可以简单地通过
Repository repo = new URLRemoteRepository("http://localhost:8080/rmi");
它工作正常,但这种方法似乎不适用于 Oak。
Oak 默认不启用 RMI 吗?是否有不同的 URI 可供使用?
但是,Oak 的文档说“Oak 带有一个可运行的 jar”,并且可运行的 jar提供了server
启动服务器的方法,所以我假设我上面的场景是有效的。