starter
starter copied to clipboard
Groovy console example searching apps folder.
Do you have any examples of groovy scripts searching apps folder content? Apps folder appears in resource browser but can’t be searched.
Hi, I assume the problem is that you are using JCR queries. Am I right? If so, it won't work because we use Bundle Resources which can't be found by JCR queries. They require tree-traversal methods to find resources.
Here is just an example of a script listing all the components (with the usage of Sling Query):
import static org.apache.sling.query.SlingQuery.$
import org.apache.sling.query.api.SearchStrategy
def root = resourceResolver.getResource("/apps")
def components = $(root).searchStrategy(SearchStrategy.DFS).find("ws:Component")
components.iterator().forEachRemaining {component ->
println "Found: $component"
}
Thanks I will try. Yes was using JCR queries. :)
@wildone we are using Sling Feature Model. To add a new library like Sling Query, you need to declare it in your distribution/src/main/features/<project-name>.json file
The declaration is:
{
"id": "org.apache.sling:org.apache.sling.query:4.0.4",
"start-order": "25"
}
In my project it would be:

@wildone we are using Sling Feature Model. To add a new library like Sling Query, you need to declare it in your
distribution/src/main/features/<project-name>.json file
The declaration is:
{ "id": "org.apache.sling:org.apache.sling.query:4.0.4", "start-order": "25" }
In my project it would be:
![]()
Yes I am, using the archetype.