programmatically access the AEM JCR | Community
Skip to main content
Level 2
March 10, 2022
Solved

programmatically access the AEM JCR

  • March 10, 2022
  • 2 replies
  • 3642 views

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?lang=en
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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Jineet_Vora

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

2 replies

Jineet_Vora
Community Advisor and Adobe Champion
Jineet_VoraCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
March 10, 2022

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

sham1Author
Level 2
March 11, 2022

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)

Vijayalakshmi_S
Level 10
March 11, 2022

@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)

DEBAL_DAS
New Member
March 11, 2022

Please refer this : Solved: Re: Unable to access AEM author using getRepositor... - Adobe Experience League Community - 442033 . 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.

Debal Das, Senior AEM Consultant
January 4, 2024

Hi everyone,

I found that the sample works with jackrabbit-standalone-2.14.10.jar, but doesn't work with other new versions like jackrabbit-standalone-2.16.10.jar or jackrabbit-standalone-2.20.13.jar.

 

So, my recommendation is just to use 2.14.10.