I am trying to get the session and resource resolver in a standalone Java code outside of AEM.
I am able to get the session but unable to get the resource resolver from the session.
Facing Null pointer exception.
Attaching screenshots for reference.
getting below exception , please note that the session is not null.
Any help will be appreciated.
From the code snippet shared and name of Java class file(ImportAssetsToDam), could assume that are trying to Import Assets to DAM from Standalone Java code.
If it is for the reason of one time activity, you can make use of Groovy Scripts where accessing objects/APIs are ease or you can write a OSGI Servlet/ Service outside of project code base, so that same can be started/stopped independently.
Please do share the reason/need for writing this as Standalone Java code.
Accessing Sling Service APIs(ResourceResolverFactory) outside AEM is an overhead. Explanation justifying this on https://stackoverflow.com/questions/41708758/aem-sling-how-to-create-resourceresolverfactory-in-a-st...
Rightly pointed out by @BrianKasingli that it is supposed to be Jcr API so the concept of ResourceResolver is not applicable as it uses sling API which is higher abstract level. You need to use the node level operations using JCR node interface.
Can you let me know the use-case of why you might need the resource resolver from a non-AEM application? Because the javax.jcr.Session should allow CRUD (Create Read Update Delete) in your Java Content Repository.
You should use the getServiceResourceResolver() to get the resource resolver from Resource Resolver Factory.
Here is the sample code to get the service resource resolver.