从外部独立应用程序

时间:2016-09-06 05:33:15

标签: cq5 aem

我正在尝试从独立的Java应用程序访问CQ / AEM存储库,但在执行主线程时遇到错误

  

线程“main”中的异常java.util.ServiceConfigurationError:javax.jcr.RepositoryFactory:Provider org.apache.jackrabbit.jcr2dav.Jcr2davRepositoryFactory无法实例化       在java.util.ServiceLoader.fail(未知来源)       at java.util.ServiceLoader.access $ 100(未知来源)       at java.util.ServiceLoader $ LazyIterator.nextService(Unknown Source)       at java.util.ServiceLoader $ LazyIterator.next(Unknown Source)       at java.util.ServiceLoader $ 1.next(Unknown Source)       在org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:192)       在org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:263)       at pwcnew.RepositoryAccessFromOutside.main(RepositoryAccessFromOutside.java:19)   引起:java.lang.NoClassDefFoundError:org / apache / jackrabbit / jcr2spi / config / RepositoryConfig       at java.lang.Class.getDeclaredConstructors0(Native Method)       at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)       at java.lang.Class.getConstructor0(Unknown Source)       在java.lang.Class.newInstance(未知来源)       ......还有6个   引起:java.lang.ClassNotFoundException:org.apache.jackrabbit.jcr2spi.config.RepositoryConfig       at java.net.URLClassLoader.findClass(Unknown Source)       at java.lang.ClassLoader.loadClass(Unknown Source)       at sun.misc.Launcher $ AppClassLoader.loadClass(Unknown Source)       at java.lang.ClassLoader.loadClass(Unknown Source)       ......还有10个

java类是:

import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.Node;
import org.apache.jackrabbit.commons.JcrUtils;
public class RepositoryAccessFromOutside {

    public static void main(String[] args) {
        Session repoSession = null;

        try {
            System.out.println("inside the class");
            final String path = "http://localhost:4502/crx/server";
            Repository myReposioty = JcrUtils.getRepository(path);

            repoSession = myReposioty.login(new SimpleCredentials("admin",
                    "admin".toCharArray()));

            Node rootNode = repoSession.getRootNode();
            System.out.println("Root Node::" + rootNode.toString());
            repoSession.save();
            repoSession.logout();

        } catch (RepositoryException e) {
            // TODO Auto-generated catch block
            System.out.println("Exception is" + e.getMessage());
        }

    }

}

任何人都可以帮助我。 提前谢谢......

1 个答案:

答案 0 :(得分:1)

从异常堆栈跟踪中,看起来您的程序在其类路径中缺少jackrabbit-jcr2spi库。

https://mvnrepository.com/artifact/org.apache.jackrabbit/jackrabbit-jcr2spi

旁注:我希望您知道AEM在apache sling API上托管JCR,它通过宁静的API提供对JCR的无缝访问。希望这会有所帮助。