Tuesday 30 October 2012

A detailed analysis of a Maven POM for an Adobe CQ5 OSGi Bundle

This article describes everything about the Maven POM which is used to build an OSGi Bundle for CQ5.

Important summary items

  • The “packaging” directive must be set to “bundle”.
  • Look at the bundles listed in Felix and make sure that your dependency list specifies the correct version numbers. 
  • Version numbers are becoming mandatory, so always specify them.
  • The encoding for source & target files can be set in a global <encoding> property & will apply throughout your build.
  • Use profiles to define different installation locations (not shown here).

POM.xml

The POM first line, complete with name-spaces :-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

Tell Maven which model version of the POM this is:

     <modelVersion>4.0.0</modelVersion>

Define project specific attributes:   
     <groupId>com.day.cq5.lily</groupId>
     <artifactId>lily-cq5-core</artifactId>
     <version>0.0.2-SNAPSHOT</version>
     <name>CQ5 Lily Core</name>
     <description>Contains the blah blah.</description>

The packaging definition is very important!!  This tells maven about the output format that it must produce (in order to produce an OSGi bundle, we need the maven-bundle-plugin): 
     <packaging>bundle</packaging>




The properties section defines some variable which we use further on within the POM.
     <properties>
          <encoding>utf-8</encoding>
          <devserver>http://localhost:4502/system/console/install</devserver>
          <devuser>admin</devuser>
          <devpassword>admin</devpassword>
     </properties>

Next, we tell Maven to use our local CQ5 instance as a repository of dependencies (an Archiva repository).  You need to install the CQ Archiva servlet (see dev.day.com).
     <repositories>
        <repository>
            <id>localinstance</id>
            <name>CQ 5.x localinstance</name>
            <url>http://localhost:4502/maven/repository</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
     </repositories>

     <pluginRepositories>
        <pluginRepository>
            <id>localinstance</id>
            <name>CQ 5.x localinstance</name>
            <url>http://localhost:4502/maven/repository</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
     </pluginRepositories>
The above is optional – if you have access to a full repository, then maybe use that instead.  This could be defined in settings.xml but is kept here so that it is visible to this project.

We now take a look at the build definition for the OSGi bundle.
This is driven by the defined plugin definitions which have goals that default to the default Maven life cycle phases.

The compiler plugin controls the javac compilation.  Note that java 1.5 is used by default therefore, here we have specified the use of Java 1.6.
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

The bundle plugin controls the packaging of the output in to an OSGi bundle.  The key element here is the Export-Package element which defines the package that we want to expose in OSGi.  There are lots of additional items that can be specified here to avoid clashes with other classes loaded by the class-loader.
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                    <Export-Package>
                        com.day.cq5.lily.util.*;
                        version=${project.version}
                    </Export-Package>
                    </instructions>
                </configuration>
            </plugin>

The sling plugin is used to install the bundle in to the local CQ instance.  Note, it would probably be better to define this configuration within a profile definition so that the bundle could be installed on other CQ5 instances (such as SIT or UAT environments):
            <plugin>
                <groupId>org.apache.sling</groupId>
                <artifactId>maven-sling-plugin</artifactId>
                <version>2.1.0</version>
                     <executions>
                          <execution>
                               <id>install-bundle</id>
                               <goals>
                                    <goal>install</goal>
                               </goals>
                          </execution>
                     </executions>
                <configuration>
                          <slingUrl>${devserver}</slingUrl>
                          <user>${devuser}</user>
                          <password>${devpassword}</password>
                     </configuration>
            </plugin>
        </plugins>
    </build>

The following section defines the Java bundles that our code is dependent upon.  Note that there are some commented out dependencies which are not required in the demonstration package but, which you will probably need at some time or other.
    <dependencies>

        <dependency>
            <groupId>com.day.cq.wcm</groupId>
            <artifactId>cq-wcm-api</artifactId>
            <version>5.5.0</version>
        </dependency>

        <dependency>
            <groupId>com.day.cq</groupId>
            <artifactId>cq-commons</artifactId>
            <version>5.5.0</version>
        </dependency>

         <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.api</artifactId>
            <version>2.2.4</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
             <version>3.0.1</version>
        </dependency>

        <!--        
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.scripting.jst</artifactId>
            <version>2.0.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.apache.felix.scr.annotations</artifactId>
            <version>1.7.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.apache.felix.scr</artifactId>
            <version>1.2.0</version>
        </dependency>
          -->

    </dependencies>
Note that CQ5 ships with commons-lang3!

This following section of profiles defines some Quality Assurrance processes which can be optionally used within the project:
    <profiles>
        <profile>
            <id>runChecks</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-checkstyle-plugin</artifactId>
                        <version>2.9.1</version>
                        <executions>
                            <execution>
                                <phase>compile</phase>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <configLocation>${project.basedir}/config_rulesets/lily_checkstyle.xml</configLocation>
                            <violationSeverity>error</violationSeverity>
                            <logViolationsToConsole>true</logViolationsToConsole>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-pmd-plugin</artifactId>
                        <version>2.7.1</version>
                        <executions>
                            <execution>
                                <phase>compile</phase>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <sourceEncoding>utf-8</sourceEncoding>
                            <failurePriority>2</failurePriority>
                            <rulesets>
                                <ruleset>${project.basedir}/config_rulesets/lily_PMD.xml</ruleset>
                            </rulesets>
                            <targetJdk>1.6</targetJdk>
                            <outputDirectory>target/pmd-reports</outputDirectory>
                            <minimumPriority>2</minimumPriority>
                            <verbose>true</verbose>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

And now, we close off the POM.xml :-
</project>
 
The end.

Appendix - some useful pointers

Maven Bundle Plugin - Configuration
http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html

Maven Bundle Plugin - Goals
http://svn.apache.org/repos/asf/felix/releases/maven-bundle-plugin-2.3.7/doc/site/index.html

OSGi Sling Service Example
http://blogs.adobe.com/kmossman/2012/04/osgi-sling-service-example.html

Maven Sling Plugin - definition
http://mvnrepository.com/artifact/org.apache.sling/maven-sling-plugin/2.1.0

Maven Sling Plugin - project home
http://sling.apache.org/site/sling.html

General Maven Pointers
http://maven.apache.org/guides/getting-started/index.html

http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

http://maven.apache.org/ref/3.0.4/maven-settings/settings.html

http://maven.apache.org/guides/mini/guide-configuring-plugins.html

http://docs.codehaus.org/display/MAVENUSER/Compiler+Plugin

http://search.maven.org/

http://mvnrepository.com/
 

29 comments:

  1. There are lots of additional items that can be specified here to avoid clashes with other classes loaded by the class-loader.
    Fall Protection Systems

    ReplyDelete
    Replies
    1. My Aem (Cq) Blog: A Detailed Analysis Of A Maven Pom For An Adobe Cq5 Osgi Bundle >>>>> Download Now

      >>>>> Download Full

      My Aem (Cq) Blog: A Detailed Analysis Of A Maven Pom For An Adobe Cq5 Osgi Bundle >>>>> Download LINK

      >>>>> Download Now

      My Aem (Cq) Blog: A Detailed Analysis Of A Maven Pom For An Adobe Cq5 Osgi Bundle >>>>> Download Full

      >>>>> Download LINK W2

      Delete
  2. One of the biggest challenges that organizations face today is having inaccurate data and being unresponsive to the needs of the Adobe CQ5 CMS Email List organization.

    ReplyDelete

  3. Very nice post. It’s a very useful and outstanding blog. Call us at Adobe Help Number UK and Adobe Support Number UK to get quick and satisfy solution.

    ReplyDelete
  4. If you need to het really useful resume writing advices, you can read https://resumecvwriter.com/blog/how-to-write-resume-job-description I am sure that here you will find what you need and impress your employer.

    ReplyDelete
  5. A befuddling web diary I visit this blog, it's incredibly grand. Strangely, in this present blog's substance made motivation behind fact and sensible. The substance of information is instructive
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training

    ReplyDelete
  6. I'm unexpirienced in this topic, but I hope to become more prudent regarding your blog.
    By the way I'm creator of essay editor visit my page today and download free essay example or have your paper edited!

    ReplyDelete
  7. Drug rehab advisors more likely than not settled any homophobic perspectives they may have and comprehend the issues explicit to the GLBT people group, for example, heterosexism, disguised homophobia, coming out and others.
    inspirational quotes for addiction
    rehab quotes

    ReplyDelete
  8. Good Blog with good Information.we will provide AEM application services https://www.nextrow.com/adobe-experience-manager

    ReplyDelete
  9. An interesting solely grown-up content internet based life stage, sharesome. This NSFW site permits posting of pornographic photographs, recordings, and connections.

    So far there are heaps of posts enveloping specialties, for example, beginner, MILF, lesbian, fingering, servitude, Hentai, POV, gay, shemales among others with a huge

    number of following. All things considered, iseems beautiful genuine with a lot of different exercises to embrace. I likewise saw that two or three YesPornPlease sites

    have just discovered their home there and you ought to presumably check whether your preferred ones are there before joining.
    yespornplease

    ReplyDelete
  10. When I attempt to use QuickBooks in multi-user mode, I am getting QuickBooks error code H202. This error code shows that the multi-user connection to the server is completely blocked. I am passing through this error code from the last week, hence I am not able to work on my QuickBooks. When this error code takes place, I fail to open a company file placed on another computer system. This error code is a very painful and frustrating, hence I want to resolve this error code. So anyone can help me to solve QuickBooks error code H202.

    ReplyDelete
  11. Printers become too popular these days because we need to print and scan documents on daily basis. But sometimes you may face printer in an error state message while printing a job due to faulty printer. If you don’t know the actual reason why you are getting the printer in error state message then get help from experts.

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. Environmental Law Assignment Help alludes to undertakings that are readied taking in to think the arrangement of rules, guidelines, and laws that oversee human communication with the indigenous habitat. These are the resolutions that depend on certain key ideas pointed toward shielding the environment from human exercises.

    ReplyDelete
  15. You are very articulate and explain your ideas and opinions clearly leaving no room for miscommunication. Please Kindly check My web: yoyomedia.

    ReplyDelete
  16. Flash file is used to upgrade or reinstall operating system in your device. It resolves different issues like application stopped working, Boot loop issue, dead issues and IMEI issues.Infocus bingo 21 flash file

    ReplyDelete
  17. Indeed yespornplease presents to you the best free pornography recordings you can discover on the net.

    That is the reason yespornplease is your best choice with regards to picking XXX porno. You can't, and you would prefer not to pass up all that we've gathered for your delight. You would not quit watching the best recordings realizing which is the page where you will discover them. You have effectively discovered it and you can not miss the second to load up with joy taking a gander at the most sweltering and tasty Internet. All deliberately chose with the goal that every video puts you at a thousand and you generally need to return for additional. Of that we are certain, you will like such a lot of that you will return.

    We as a whole know the xxx recordings of yespornplease however on our site you can discover the cream de la cream, separating the inferior quality substance. You will presently don't need to sit around investigating recordings and picking the ones with the best quality and substance, we will do it for you.

    We're staying put and you'll wind up thinking of us as the best form of yespornplease we buckle down for. We need to please tastes and stay perpetually, we realize that this is accomplished exclusively by offering quality and that is our main thing. That is the reason we welcome you to visit us. We realize that once you see the nature of our material, you will get diligent to our page.
    A page where your porno minutes will be the most agreeable and best. You will not need to move from here. You can appreciate and fill yourself with joy without leaving our site briefly.

    Need to see free versatile pornography in excellent and HD?

    On our site you will appreciate watching the best yespornplease.com motion pictures. We sincerely feel that our guests merit what we think they merit. Great, enduring, top notch motion pictures. They merit not to lose subtleties of the scenes introduced by every film they need to see. That is conceivable, in light of the fact that we have an assortment of the best films in HD quality. So you can appreciate the best of the most sultry and distorted snapshots of every video you need to see.

    Yespornplease is the ideal spot to observe free pornography video here you will track down the best pornography recordings of the whole organization.
    In the event that you can appreciate quality and assortment here. Yespornplease have great material, complimentary and we are continually reestablishing. So you can be certain that with us your fun and joy won't ever end. Try not to make due with something tolerably great, in case you will track down the best on this page.

    We offer free pornography video XXX so you can make the most of your sexuality

    Why yespornplease and not another page?
    Since there could be no other spot like Yes pornography where to observe free pornography recordings of the greatest HD quality and totally horny, similar to our site. Make the most of your sexuality to the greatest, make some great memories and get those climaxes you need such a huge amount with the material we have for you.

    yespornplease is the spot, come in and you will consider that to be with the expectation of complimentary pornography films we have no opposition. We are the awesome. There could be no other equivalent and there will not be. We work pondering your fulfillment consistently. We search for simply the best material.

    ReplyDelete
  18. The easiest way to get more views on your Instagram page. Buy Instagram views from SMM panel. Post consistently on your social media page or create your profile more attractive. These steps help you for growth your page organically. For more information You can connect with our website.
    Buy Instagram views

    ReplyDelete
  19. Avail Expert homework help United States and make things easy for yourself. Connect with Academic Writers & never miss an homework deadline. Subject-Wise homework Help In USA.

    ReplyDelete
  20. Our paper helper is available online that provides expert-written paper writing assistance to students who fail to complete their school, university, and college tasks over time.

    ReplyDelete
  21. Desklib offers
    homework help
    task that will help you in getting great imprints during assessment. Desklib associates you with our master through visit meetings so you can learn and find every one of the solutions precisely.

    ReplyDelete
  22. In case you are confronting any trouble and need direction in the homework help where you are stuck, we have a pool of exceptionally qualified schoolwork partner at Desklib. Our mentors are specialists, who have long stretches of involvement with the field of academics.

    ReplyDelete
  23. NICE POST. It is so connective. If you want to explore more blog on this topic, visit at sourceessay.com and get free samples from homework help team.

    ReplyDelete
  24. Wow great post! Thankyou for sharing the information, its very helpful. I want share about Aaraa couture

    ReplyDelete
  25. My Aem (Cq) Blog: A Detailed Analysis Of A Maven Pom For An Adobe Cq5 Osgi Bundle >>>>> Download Now

    >>>>> Download Full

    My Aem (Cq) Blog: A Detailed Analysis Of A Maven Pom For An Adobe Cq5 Osgi Bundle >>>>> Download LINK

    >>>>> Download Now

    My Aem (Cq) Blog: A Detailed Analysis Of A Maven Pom For An Adobe Cq5 Osgi Bundle >>>>> Download Full

    >>>>> Download LINK AO

    ReplyDelete
  26. Take my best online class help for me to get the finish my online class takers whom you can I Take My Online Class For Me, Pay For Someone To Take Online Class and Pay For Online Classes services experts.

    ReplyDelete
  27. Get Help with MIS605 Systems Analysis and Design Assessment

    MIS605 Systems Analysis and Design

    Get Help with MIS605 Systems Analysis and Design Assessment with Punjab Assignment Help at an affordable price and timely delivery. We have Experts on the team.

    MIS605 Systems Analysis and Design Assessment

    MIS605 Systems Analysis and Design Assessment

    MIS605 Systems Analysis and Design Assessment

    ReplyDelete