Developing CQ5 Components and OSGi bundles with maven

If you’re starting CQ5 development in multi-developer production environment, it is really useful to be able to generate a new project structure quickly and get code built and deployed to dev instances without too much pain.

Two really convenient archetypes provided by Adobe are simple-content-package-archetype and multimodule-content-package-archetype.

This URL has the details: http://dev.day.com/docs/en/cq/current/core/how_to/how_to_use_the_vlttool/vlt-mavenplugin.html#Using Archetypes To Generate CQ Projects

Assuming you have maven installed and the following profile installed in your maven settings.xml file.

<profile>
    <id>adobe-public</id>

    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>

    <properties>
         <releaseRepository-Id>adobe-public-releases</releaseRepository-Id>
         <releaseRepository-Name>Adobe Public Releases</releaseRepository-Name>
         <releaseRepository-URL>
           http://repo.adobe.com/nexus/content/groups/public
         </releaseRepository-URL>
   </properties>

   <repositories>
      <repository>
          <id>adobe-public-releases</id>
               <name>Adobe Public Repository</name>
               <url>http://repo.adobe.com/nexus/content/groups/public</url>
               <releases>
                  <enabled>true</enabled>
                  <updatePolicy>never</updatePolicy>
               </releases>
               <snapshots>
                  <enabled>false</enabled>
               </snapshots>
               </repository>
            </repositories>

            <pluginRepositories>
                <pluginRepository>
                    <id>adobe-public-releases</id>
                    <name>Adobe Public Repository</name>
                    <url>http://repo.adobe.com/nexus/content/groups/public</url>
                    <releases>
                      <enabled>true</enabled>
                      <updatePolicy>never</updatePolicy>
                    </releases>
	            <snapshots>
	               <enabled>false</enabled>
	            </snapshots>
	        </pluginRepository>
	   </pluginRepositories>
</profile>

After this, open a commandline and run one of the maven archetype commands in the URL above.

e.g.

mvn archetype:generate -DarchetypeGroupId=com.day.jcr.vault 
-DarchetypeArtifactId=simple-content-package-archetype -DarchetypeVersion=1.0.0 
-DarchetypeRepository=adobe-public-releases

After putting all the details of your new projects, if you run

mvn clean install

You should get a new CQ5/CRX package created in your target folder. To install this to CQ5, assuming you’re running http://localhost:4502, you need to run install

mvn clean install -PautoInstallPackage

There is a slight problem with the pom.xml generated in that it does not include the CQ5 user and password to be able to install the package. Make the following change to the content/pom.xml file:

<plugin>
	<groupId>com.day.jcr.vault</groupId>
	<artifactId>content-package-maven-plugin</artifactId>
	<extensions>true</extensions>
	<configuration>
		<name>mytest-content-package</name>
		<group>mytest</group>
		<filters>
			<filter>
				<root>/apps/mytest</root>
				<includes>
				<include>/apps/mytest(/.*)?</include>
				<include>/apps/mytest/install</include>
			</includes>
			<excludes>
			        <exclude>.*/rep\:accessControl$</exclude>
				</excludes>
			</filter>
	</filters>
  <targetURL>http://${crx.host}:${crx.port}${crx.context}/crx/packmgr/service.jsp</targetURL>
	<useProxy>false</useProxy>
	<userId>${crx.user}</userId>
	<password>${crx.pass}</password>
</configuration>
</plugin>

Set the variables crx.host and crx.pass somewhere in your parent folder’s pom.xml as follows:

  <properties>
        <crx.host>localhost</crx.host>
        <crx.port>4502</crx.port>
		<crx.user>admin</crx.user>
		<crx.pass>admin</crx.pass>
		<crx.context></crx.context>
    </properties>

Once you do this, running mvn clean install -PautoInstallPackages should deploy (and update) the package in CQ5 successfully.

Having coding!

– Sarwar Bhuiyan

Advertisements
Developing CQ5 Components and OSGi bundles with maven

5 thoughts on “Developing CQ5 Components and OSGi bundles with maven

  1. Tom says:

    Hello,

    Basically I have followed above howto and this is not working as i have received following error that archetype doesnt exists.

    So, please advise…

    Thanks
    Tom

    [INFO] Archetype defined by properties
    Downloading: http://repo.adobe.com/nexus/content/groups/public/com/day/jcr/vault/multimodule-content-package-archetype/1.0.2/multimodule-content-package-archetype-1.0.0.jar

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate (default-cli) on project standalone-pom: The desired archetype does not exist (com.day.jcr.vault:multimodule-content-package-archetype:1.0.0) -> [Help 1]

  2. Tom says:

    Please see output using exactly the same command as on the web.

    Please advise…

    Thanks
    Tom

    [INFO] ————————————————————————
    [INFO] BUILD FAILURE
    [INFO] ————————————————————————
    [INFO] Total time: 1.094s
    [INFO] Finished at: Fri Aug 30 20:21:07 CEST 2013
    [INFO] Final Memory: 11M/245M
    [INFO] ————————————————————————
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2
    .2:generate (default-cli) on project standalone-pom: The desired archetype does
    not exist (com.day.jcr.vault:simple-content-package-archetype:1.0.0) -> [Help 1]

    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
    rg.apache.maven.plugins:maven-archetype-plugin:2.2:generate (default-cli) on pro
    ject standalone-pom: The desired archetype does not exist (com.day.jcr.vault:sim
    ple-content-package-archetype:1.0.0)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
    .java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
    .java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
    .java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
    ct(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
    ct(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBu
    ild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecycl
    eStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:318)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:153)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
    cher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
    a:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
    uncher.java:414)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
    357)
    Caused by: org.apache.maven.plugin.MojoFailureException: The desired archetype d
    oes not exist (com.day.jcr.vault:simple-content-package-archetype:1.0.0)
    at org.apache.maven.archetype.mojos.CreateProjectFromArchetypeMojo.execu
    te(CreateProjectFromArchetypeMojo.java:221)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(Default
    BuildPluginManager.java:106)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
    .java:208)
    … 19 more
    Caused by: org.apache.maven.archetype.exception.UnknownArchetype: The desired ar
    chetype does not exist (com.day.jcr.vault:simple-content-package-archetype:1.0.0
    )
    at org.apache.maven.archetype.ui.generation.DefaultArchetypeGenerationCo
    nfigurator.configureArchetype(DefaultArchetypeGenerationConfigurator.java:117)
    at org.apache.maven.archetype.mojos.CreateProjectFromArchetypeMojo.execu
    te(CreateProjectFromArchetypeMojo.java:205)
    … 21 more
    [ERROR]
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please rea
    d the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureExc

    1. Nivaz Deen says:

      Hi tom,

      please verify whether you have followed the following things.
      1. latest version of mvn.
      2.proper inclusion of which you find in the first part of this page inside settings.xml of your maven (apache-maven-3.1.0\conf\settings.xml). make sure you dint add it in the comment part..

      Regards,
      Nivaz Deen

  3. sandeep kantimahanthi says:

    Hello Sarwar & Niwaz,

    Thanks its working 🙂 …

    Could you also give some example of how to deploy a working bundle onto cq5 ..

    rgds,
    Sandeep.K

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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