Expand my Community achievements bar.

SOLVED

Unable to access AEM author using getRepository

Avatar

Level 3

Hi All,

    Any one could help me in resolving the following issue as I am not able to access the AEM repository using the following code :

Repository repository = JcrUtils.getRepository("http://localhost:4502/crx/server");
//Create a Session- put a valid creds who has the access of the repository
javax.jcr.Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray()));

after executing this piece of code I am getting the following issue :

2022-02-24 11:12:30.001 ERROR [com.myaem65trainings.core.schedulers.DeleteNodeWithScheduler] Error Captured during :: 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:
Perhaps the repository you are trying to access is not available at the moment.

 

Can anyone please help me in this.

Thanks,

Pavan 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @MandaPavanKumar 

 

If you are trying to access AEM JCR repo from a JAVA standalone application then you have to add the jackrabbit-standalone-2.4.0.jar file to your Java application’s class path. Here is an article to access JCR repo programatically. https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/access-jcr.html?la...

 

If you are trying to access the JCR repo from an AEM application then there few different ways you could that. One of the most used and recommended way is get the resourceResolver from a service user.

  1. Create a service user.
    https://experienceleague.adobe.com/docs/experience-manager-64/administering/security/security-servic...
  2. Provide required permission to the service user.
  3. Get the resourceResolver using the service user.
    final Map<String, Object> param = Collections.singletonMap(ResourceResolverFactory.SUBSERVICE,
    <SERVICE_USER_NAME>);
    resourceResolver = resourceResolverFactory.getServiceResourceResolver(param);
    Here is an article that might help you.

    Thanks,

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @MandaPavanKumar 

 

If you are trying to access AEM JCR repo from a JAVA standalone application then you have to add the jackrabbit-standalone-2.4.0.jar file to your Java application’s class path. Here is an article to access JCR repo programatically. https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/access-jcr.html?la...

 

If you are trying to access the JCR repo from an AEM application then there few different ways you could that. One of the most used and recommended way is get the resourceResolver from a service user.

  1. Create a service user.
    https://experienceleague.adobe.com/docs/experience-manager-64/administering/security/security-servic...
  2. Provide required permission to the service user.
  3. Get the resourceResolver using the service user.
    final Map<String, Object> param = Collections.singletonMap(ResourceResolverFactory.SUBSERVICE,
    <SERVICE_USER_NAME>);
    resourceResolver = resourceResolverFactory.getServiceResourceResolver(param);
    Here is an article that might help you.

    Thanks,

Avatar

Employee Advisor

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

 

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

 

As we could see I have added using Build Path[jackrabbit-standalone-2.4.0.jar(https://archive.apache.org/dist/jackrabbit/2.4.0/)] and able to access repository -

 

DEBAL_DAS_0-1645715257586.png

 

DEBAL_DAS_1-1645715275561.png

Able to persist node and property as shown below -

DEBAL_DAS_2-1645715561516.png

 

I have used AEM 6.5.9