Just another site

Using Maven to Create and Install CQ5 Package

Creating components using CRXDE and CRXDE Lite can be frustrating. Both are buggy and are different environments than what you are use to working with. You can use Maven to create a package that it can then install the package in CQ5.

If you have ever extracted a package then you’ll see that there are two folders within it, jcr_root and META-INF. Both of these files are important and they determine how the Maven project should be setup. META-INF holds the filters (paths) that the package contains. jcr_root has all of your files for components, templates, etc. I typically put these files in src/main/content in the Maven project so my code will have that path.

First thing you need to do is in pom.xml under <build> add the following code so that it knows to include your files in the bundle. This also excludes any file vault (VLT) files.

    <!-- filter meta information to get some properties into the files -->
    <!-- exclude .vlt control files and tests -->

Next you need to setup a profile that uses Groovy to install the package to CQ5 using POST.

                                import org.apache.commons.httpclient.*
                                import org.apache.commons.httpclient.methods.*
                                import org.apache.commons.httpclient.auth.*
                                import org.apache.commons.httpclient.methods.multipart.*

                                //method declaration for execute of PostMethod
                                def executePost(httpclient, httppost, outputResponse){
                                    try {
                                        if (outputResponse){
                                            println httppost.responseBodyAsString
                                    } catch (Exception e) {
                                        println("exception: " + e)
                                    } finally {

                                def uploadAndInstall(hostPort, packageName, projectRoot, httpclient){
                                    //upload package
                                    def httppost = new PostMethod('http://' + hostPort + '/crx/packmgr/service.jsp')
                                    def file = new File(projectRoot + '/target/' + packageName + '.jar')

                                    println("Installing package" +packageName+" to " + hostPort)


                                        def parts = [new FilePart("file", file)] as Part[]
                                        httppost.setRequestEntity(new MultipartRequestEntity(parts,

                                        executePost(httpclient, httppost, true)

                                        //install package
                                        def installURL = 'http://' + hostPort +
                                        '/crx/packmgr/service/.json/etc/packages/' + packageName + '.zip'
                                        println('INASTALL: ' + installURL)
                                        httppost = new PostMethod(installURL)
                                        httppost.addParameter("cmd", "install")

                                        executePost(httpclient, httppost, true)
                                    } else {
                                        println("File does not exist for " + packageName + ". Not Deploying.")

                                def user =['cquser']
                                def pass =['cqpassword']
                                def packageName =['packageName']
                                def projectRoot =['projectDir']

                                // set up the client
                                def httpclient = new HttpClient()
                                def defaultcreds = new UsernamePasswordCredentials(user, pass)
                                httpclient.getState().setCredentials(AuthScope.ANY, defaultcreds)

                                println "CQSERVERS:" +['cqservers']

                      ['cqservers'].tokenize(',').each {
                                    uploadAndInstall(it, packageName, projectRoot, httpclient)

            <!-- Compile Java classes for OSGi bundle -->

When building the project make sure you select the installUi profile or if you are using the command line add the argument -DinstallUI and it will automatically install the package into CQ5.

I have created a sample project that contains everything you need that you can download here:


Single Post Navigation

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: