Recently, I had to configure jolokia in my grails application. Jolokia is a JMX-HTTP bridge giving an alternative to JSR-160 connectors. Grails doesn’t provide web.xml directly to configure but you can do it by installing the templates. Just issue the following command on the terminal to install them:

grails install-template

This will install the templates in APP_ROOT/src/templates and you can find the web.xml at APP_ROOT/src/templates/war/web.xml.

Configuring the servlet is quite easy with the grails plugin. You can find the deployment descriptor closure in your plugin descriptor and configure servlets like:

def doWithWebDescriptor = { xml ->
        def servlets = xml.'servlet'
        servlets[servlets.size() - 1] + {
            servlet {
                'servlet-name'('jolokia-agent')
                'servlet-class'('org.jolokia.http.AgentServlet')
            }
        }

        def mappings = xml.'servlet-mapping'
        mappings[mappings.size() - 1] + {
            'servlet-mapping' {
                'servlet-name'('jolokia-agent')
                'url-pattern'('/jolokia/*')
            }
        }
    }