Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

programmatically access the AEM JCR

Avatar

Level 2

I'm trying to follow this example from Adobe in a different way as mentioned below....
https://experienceleague.adobe.com/docs/experience-manager-65/developing/platform/access-jcr.html?la...
MY Code: public class CreatingJcrNodes { public static void main(String[] args) throws Exception { try { //Create a connection to the CQ repository running on local host Repository repository = JcrUtils.getRepository("
http://localhost:4502/crx/server"); //Create a Session javax.jcr.Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray())); //Create a node that represents the root node Node root = session.getRootNode(); // Store content Node adobe = root.addNode("adobe"); Node day = adobe.addNode("day"); day.setProperty("message", "Adobe CQ is part of the Adobe Digital Marketing Suite!"); // Retrieve content Node node = root.getNode("adobe/day"); System.out.println(node.getPath()); System.out.println(node.getProperty("message").getString()); // Save the session changes and log out session.save(); session.logout(); } catch(Exception e){ e.printStackTrace(); } } }

Error : javax.jcr.RepositoryException: Unable to access a repository with the following settings:

I've found a number of articles both here and on other sites but none of the suggestions I've found have done anything to resolve the issue.

1 Accepted Solution

Avatar

Correct answer by
Level 5

Hi @sham1, can you please print the remaining log stack trace?

Looks like some some repository settings are missing from Error "Error : javax.jcr.RepositoryException: Unable to access a repository with the following settings:"

 

I tried with a standalone Java project and downloaded the https://dlcdn.apache.org/jackrabbit/2.14.10/jackrabbit-standalone-2.14.10.jar as reference library and was able to create a node in my JCR repository with the following code:

/*
 * This Java Quick Start uses the jackrabbit-standalone-2.14.10.jar file
 * https://dlcdn.apache.org/jackrabbit/2.14.10/jackrabbit-standalone-2.14.10.jar
 */

import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.Node;

import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.jackrabbit.core.TransientRepository;

public class GetRepository {

public static void main(String[] args) throws Exception {

try {

    //Create a connection to the CQ repository running on local host
    Repository repository = JcrUtils.getRepository("http://localhost:4503/crx/server");

   //Create a Session
   javax.jcr.Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray()));

  //Create a node that represents the root node
  Node root = session.getRootNode();

  // Store content
  Node adobe = root.addNode("adobe");
  Node day = adobe.addNode("day");
  day.setProperty("message", "Adobe CQ is part of the Adobe Digital Marketing Suite!");

  // Retrieve content
  Node node = root.getNode("adobe/day");
  System.out.println(node.getPath());
  System.out.println(node.getProperty("message").getString());

  // Save the session changes and log out
  session.save();
  session.logout();
  }
 catch(Exception e){
  e.printStackTrace();
  }
 }
}

- Jineet

View solution in original post

4 Replies

Avatar

Correct answer by
Level 5

Hi @sham1, can you please print the remaining log stack trace?

Looks like some some repository settings are missing from Error "Error : javax.jcr.RepositoryException: Unable to access a repository with the following settings:"

 

I tried with a standalone Java project and downloaded the https://dlcdn.apache.org/jackrabbit/2.14.10/jackrabbit-standalone-2.14.10.jar as reference library and was able to create a node in my JCR repository with the following code:

/*
 * This Java Quick Start uses the jackrabbit-standalone-2.14.10.jar file
 * https://dlcdn.apache.org/jackrabbit/2.14.10/jackrabbit-standalone-2.14.10.jar
 */

import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.Node;

import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.jackrabbit.core.TransientRepository;

public class GetRepository {

public static void main(String[] args) throws Exception {

try {

    //Create a connection to the CQ repository running on local host
    Repository repository = JcrUtils.getRepository("http://localhost:4503/crx/server");

   //Create a Session
   javax.jcr.Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray()));

  //Create a node that represents the root node
  Node root = session.getRootNode();

  // Store content
  Node adobe = root.addNode("adobe");
  Node day = adobe.addNode("day");
  day.setProperty("message", "Adobe CQ is part of the Adobe Digital Marketing Suite!");

  // Retrieve content
  Node node = root.getNode("adobe/day");
  System.out.println(node.getPath());
  System.out.println(node.getProperty("message").getString());

  // Save the session changes and log out
  session.save();
  session.logout();
  }
 catch(Exception e){
  e.printStackTrace();
  }
 }
}

- Jineet

Avatar

Level 2

Hi ,

    This is the full error log..

 

 

javax.jcr.RepositoryException: Unable to access a repository with the following settings:
org.apache.jackrabbit.repository.uri: http://localhost:4502/crx/server
The following RepositoryFactory classes were consulted:
org.apache.jackrabbit.core.RepositoryFactoryImpl: 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:224)
at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:264)
at CreatingJcrNodes.main(CreatingJcrNodes.java:16)

Avatar

Community Advisor

@sham1 

Check if your local AEM instance is up and running (by accessing http://localhost:4502/crx/server

in your browser) / accessible from where you are executing your standalone code. (provided you have the jackrabbit-standalone jar correctly in your class path as mentioned in the doc)

 

javax.jcr.RepositoryException: Unable to access a repository with the following settings:
org.apache.jackrabbit.repository.uri: http://localhost:4502/crx/server
The following RepositoryFactory classes were consulted:
org.apache.jackrabbit.core.RepositoryFactoryImpl: 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:224)
at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:264)
at CreatingJcrNodes.main(CreatingJcrNodes.java:16)

Avatar

Community Advisor

Please refer this : Solved: Re: Unable to access AEM author using getRepositor... - Adobe Experience League Community - ... . Here we have added screenshots with details and it will help you.

 

If you are planning to write a stand alone Java class or stub to access AEM repository then you could follow this approach.

 

But if you are planning to access from OSGi service then use service user to access AEM repository.