Create AEM Multi Module Project using Eclipse
The focus of this tutorial is to learn how to AEM Multi Module Project and build it using maven. This tutorial is intended for AEM beginners who are facing issue in setting up their eclipse work space.
I personally like this tutorial very much as it clear lot of basics and recommend it for advanced developers also to go through it once. If you want to learn how to create or setup a new project in AEM from scratch and how to sync data between eclipse and crxde .
After completing this tutorial. you will have a clear understanding of:-
- How to install AEM plugin in eclipse.
- How to create AEM multi module project using aem plugin.
- Modifying pom.xml for custom profiles.
- Build aem multi module project using maven.
Pre-requisites for creating a mvn archetype Project:-
- Maven should be installed. See how to install maven
- AEM instance should be up and running.
Install AEM Plugin from MarketPlace
- Open Eclipse
- Go to Help available in top bar.
- Select Eclipse Marketplace
- Search for AEM.
- Click install.
- On next screen Click Confirm.
- Accept terms and condition and click Finish.
- Press OK on Warning.
- Once installation is completed. Restart Eclipse.
Create AEM multi module project using aem plugin
- Open Eclipse.
- select File -> New project -> Select AEM Sample Multi-Module Project.
- Click Next to select Archetype
- Click Next to configure AEMÂ Archetype project
- If you expand Advanced option.
- You can see that Name maps to artifactName and appsFolderName
- Package maps to location org/training folder in your .m2 directory. during maven build your code will be copied at this location.
- Artifact Id maps to cssId. It is the unique id for your project.
- Click Next for server configuration. Select don’t deploy on server as we are going to use maven command for deployment.
- Click Finish.
- Your project structure should look like below screenshot.
Note: –Â It will take around 5-10 minutes for setting up your project structure.
AEM maven multi-module project structure
Modify pom.xml to add profiles
- Open pom.xml of aemcq5tutorials.ui.apps and aemcq5tutorials.ui.content.
- Go to profiles section and add below code.
<profile> <id>aemcq5tutorials-author</id> <properties> <crx.host>localhost</crx.host> <crx.port>4502</crx.port> <crx.username>admin</crx.username> <crx.password>admin</crx.password> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> <build> <plugins> <plugin> <groupId>com.day.jcr.vault</groupId> <artifactId>content-package-maven-plugin</artifactId> <executions> <execution> <id>install-custom-package</id> <phase>install</phase> <goals> <goal>install</goal> </goals> <configuration> <targetURL>http://${crx.host}:${crx.port}/crx/packmgr/service.jsp</targetURL> <userId>${crx.username}</userId> <password>${crx.password}</password> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile>
Similarly we can add or publish enviroment.
Note: – If you don’t have any profile with the name you are trying to build then you will get warning message during build “the requested profile could not be activated because it does not exist”.
Build AEM Multi Module project using Maven
- On your local system go to aemcq5tutorials pom.xml location.
- Open command prompt and run below command
mvn clean install -P aemcq5tutorials-author
- Once build is success
Note:- If your project is in installed state in Felix console and getting import error “javax.inject;version” . Then add below line in your project core pom.xml
<plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> <instructions> <!-- <Embed-Dependency> artifactId1, artifactId2;inline=true </Embed-Dependency> --><!-- Add below line --> <Import-Package>javax.inject;version=0.0.0,*</Import-Package> <Sling-Model-Packages> org.training.aemcq5tutorials.core </Sling-Model-Packages> </instructions> </configuration> </plugin>
Click Here to Learn How to create project in aem using maven archetype command.
Also see how to sync content from crxde to eclipse using vlt plugin.
Leave a Reply