System Administrator Jahia 7.3 Jahia 8 Legacy

Deleting a node or a site with a script


How to delete a node or a site with Groovy script?


There are different ways to delete content in Jahia such as using the UI, JCR browser or the REST API as shown in our documentation on Content manipulation. Below is a simple script to delete a node (or even an entire site) using a groovy script:

org.apache.jackrabbit.core.JahiaRepositoryImpl rep ="jackrabbit").getRepository();
javax.jcr.SimpleCredentials cred = (javax.jcr.SimpleCredentials)"system");
cred.setAttribute("org.apache.jackrabbit.autoFixCorruptions", "true");
javax.jcr.Session jcrsession = rep.login(cred, "default");
javax.jcr.Node jcrNode = jcrsession.getNode("/sites/mySite");
 A backup is strongly recommended before executing any update or delete query