How to setup Maven in your development environment

You can use Maven to build an OSGi bundle. Maven manages required JAR files that a Java project needs in its class path. Instead of searching the Internet trying to find and download third-party JAR files to include in your project’s class path, Maven manages these dependencies for you.

You can download Maven 3 from the following URL:

  1. Unzip the distribution archive, i.e. apache-maven-3.1.1-bin.zip to the directory you wish to install Maven 3.1.1. These instructions assume you chose C:\Program Files\Apache Software Foundation. The subdirectory apache-maven-3.1.1 will be created from the archive
  2. Add the M2_HOME environment variable by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button, then adding the M2_HOME variable in the user variables with the value C:\Program Files\Apache Software Foundation\apache-maven-3.1.1. Be sure to omit any quotation marks around the path even if it contains spaces. Note: For Maven   2.0.9, also be sure that the M2_HOME doesn't have a '\' as last character.
  3. In the same dialog, add the M2 environment variable in the user variables with the value %M2_HOME%\bin.
  4. Optional: In the same dialog, add the MAVEN_OPTS environment variable in the user variables to specify JVM properties, e.g. the value -Xms256m -Xmx512m. This environment variable can be used to supply extra options to Maven.
  5. In the same dialog, update/create the Path environment variable in the user variables and prepend the value %M2% to add Maven available in the command line.
  6. In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g. C:\Program Files\Java\jdk1.5.0_02 and that %JAVA_HOME%\bin is in your Path environment variable.
  7. Open a new command prompt (Winkey + R then type cmd) and run mvn --version to verify that it is correctly installed.






                Create an Adobe CQ Maven archetype project

                To create an Adobe CQ archetype project, perform these steps:

                1. Open the command prompt and go to your working directory (D:\smaple-cq-project).
                2. Run the following Maven command:
                mvn archetype:generate -DarchetypeGroupId=com.day.jcr.vault -DarchetypeArtifactId=multimodule-content-package-archetype -DarchetypeVersion=1.0.0 -DarchetypeRepository=adobe-public-releases
                3. When prompted for additional information, specify these values:
                groupId: com.test
                artifactId: cq-test-project
                version: 1.0-SNAPSHOT : 1.0.0
                package: com.aem.coe
                appsFolderName: AEM-Training
                artifactName: AEM Training
                packageGroup: AEM
                confirm: Y
                4. Once done, you will see a message like:

                Maven Plugin to Install Bundle Directly Into OSGI in AEM/Adobe CQ5


                Use the following plugin in your POM to install bundle directly into OSGI console.


                <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>http://localhost:8080/system/console/install</slingUrl>
                     <user>admin</user>
                     <password>admin</password>
                    </configuration>
                </plugin>

                Best way to use suffix in AEM/Adobe CQ5 URLs

                It is better to use the suffix with selectors only that will help the dispatcher when flush cache.

                Ex:-
                <resource path>/results.html

                <resource path>/results.html/suffix(Not recommended )

                <resource path>/results.html/suffix.suffix1  (Not recommended )

                <resource path>/results.slelector.html/suffix(Recommended)

                <resource path>/results.slelector.html/suffix.suffix1(Recommended)