Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

AEM6.5 - Deleting installed packages

Avatar

Level 7

Hello everyone,

 

I've got a task to create a service for deleting installed packages programmatically. According https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/org/apache/jackrabbit... it does existing a way doing it so. Does exists somewhere an working an example how to get access to package manager?

I am completly new on this field.

 

Thanks in advanced.

4 Replies

Avatar

Level 10

hi @Magicr

Please take a moment to review this response here.

Avatar

Level 7

Thanks for your answer.  I read this post and I come up with new question: 

According to linked post it is recommended to uninstall a package first. Unfortunatly I forgort to mention I want to delete old packages and want keep the latest three. So my question is: What will happend, if I uninstall previous version of a package, in case if it possible with curl 

Avatar

Level 4

@Magicr  You will need to have Admin access to navigate to CRX package manager. 

Step by step instructions for perform delete operation programmatically:

  1. Decide lookup method

    • By packageId (group:name:version) or by repository path (/etc/packages or /var/packages).
  2. Create a Sling service user and mapping

    • Felix config: my.bundle.symbolic.name:package-delete-service = package-delete-user
    • Grant minimal permissions on package paths.
  3. Build an OSGi service interface (PackageDeletionService) and implementation.

    • Inject ResourceResolverFactory.
  4. Acquire a secure ResourceResolver and JCR Session

    • Use ResourceResolverFactory.getServiceResourceResolver with SUBSERVICE.
    • Always close the resolver (try-with-resources).
  5. Preferred deletion: use Packaging API

    • Use org.apache.jackrabbit.vault.packaging (or com.day.cq.packaging) PackageManager / JcrPackage to locate and remove the package.
    • It handles metadata and registry cleanup.
  6. Fallback: remove JCR nodes directly

    • Validate node exists and check installed state (prevent accidental delete).
    • session.getNode(path).remove(); session.save().
  7. Safety and checks

    • Require a force boolean to delete installed packages.
    • Validate path prefixes (/etc/packages or /var/packages).
    • Log/audit each delete.
  8. Error handling and cleanup

    • Catch RepositoryException, LoginException, IOExceptions.
    • Return clear errors and ensure resourceResolver.close().
  9. Test and deploy

    • Unit tests (mock resolver/packaging).
    • Integration tests in non‑prod: create → install → delete (with/without force).
    • Deploy bundle and configure subservice mapping.

Minimal example (conceptual):

 
Map<String,Object> auth = Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, "package-delete-service"); try (ResourceResolver rr = resolverFactory.getServiceResourceResolver(auth)) { Session session = rr.adaptTo(Session.class); // Preferred: use PackageManager to open/delete package if (session.nodeExists(pkgPath)) { session.getNode(pkgPath).remove(); session.save(); } }

Avatar

Community Advisor

Hi @Magicr,

If you are using AEM 6.5 you can consider to use below tool from ACS Commons, so you may not need to implement anything custom.

However if the implementation is still the key, you can check how above feature has been implemented and how you can operate Package Manager api on code level, here is a link to sample code: