Dheerendra
Dheerendra

Reputation: 1

Accessing Cq/AEM repository from external Standalone application

i am trying to access the CQ/AEM repository from standalone java application but getting below error while executing the main thread

Exception in thread "main" java.util.ServiceConfigurationError: javax.jcr.RepositoryFactory: Provider org.apache.jackrabbit.jcr2dav.Jcr2davRepositoryFactory could not be instantiated at java.util.ServiceLoader.fail(Unknown Source) at java.util.ServiceLoader.access$100(Unknown Source) at java.util.ServiceLoader$LazyIterator.nextService(Unknown Source) at java.util.ServiceLoader$LazyIterator.next(Unknown Source) at java.util.ServiceLoader$1.next(Unknown Source) at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:192) at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:263) at pwcnew.RepositoryAccessFromOutside.main(RepositoryAccessFromOutside.java:19) Caused by: 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) at java.lang.Class.newInstance(Unknown Source) ... 6 more Caused by: 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 more

And the java class is:

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());
        }

    }

}

Can anyone help me on this. thanks in advance...

Upvotes: 0

Views: 918

Answers (1)

user1057653
user1057653

Reputation: 176

From the exception stack trace, it looks like your program is missing jackrabbit-jcr2spi library in its classpath.

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

On a side note: I hope you are aware that AEM hosts JCR on apache sling API which provides seamless access to JCR via restful API's. Hope this helps.

Upvotes: 1

Related Questions