What are archetypes?
Why we use archetypes?
Available maven archetypes for generating CQ projects!
Let’s start with the why part of the question first, so we will get to know “What are archetypes?” automatically
Why we use archetypes?
Basically, when we work with AEM, there can be multiple use cases. One may want to have a Simple CQ application, which allows developing a CQ application and one may want to have a bit advanced CQ application which allows developing a CQ application and installing resources to the server.
As a new developer or even as an experienced developer, creating a project structure is a repetitive task, which is error-prone and one needs to be very careful while creating a structure of project relevant to the requirements. Once the structure goes wrong, the rest of the things will be substantial to manage.
That is where the maven archetypes come in the picture. Maven archetypes provide us with predefined project structure templates. There are multiple archetypes provided by Maven.
What are archetypes?
The archetype can be defined as a model or an original structure from which the copies of the same structure can be made. So in terms of AEM, It can be correlated with a template. Archetypes provide us a constant, regular, uniform way of generating Maven projects. With the help of Maven archetypes, a new developer/user can be on-boarded quickly in a consistent way with the best industry practices within minutes.
Maven archetypes also include a sample project, which helps the developer/users to get introduced to best practices and features employed by maven.
Maven archetypes also help us to create Maven project templates for users, which enables the user to generate a parametrized version of the project. Even one can capture a portion project in archetype, which can be later added to existing projects.
Available maven archetypes for generating CQ projects!
As a developer, one must understand the requirements to decide on the project architecture required for the neat, consistent and successful execution of the project. There are several predefined maven archetypes for generating CQ/AEM project. Depending on the goals of the project, the developer/user must choose one of them to execute in the project.
· simple-content-package-archetype: It creates a simple project structure, which consists of the folder structure below the /apps folder of the CQ repository.
· simple-content-package-with-embedded-archetype: It also creates a content package, but this can include third-party artifacts. While creating a project you can specify the ID of the artifact to embed in the content package in parameter “embeddedArtifactId”.
· multimodule-content-package-archetype: It creates a maven project that creates a content package and a bundle to install Java classes in CRX.
Each archetype generates the following items:
· The project folder structure.
· POM files.
· FileVault configuration files.
How to create a project using archetype.
Navigate to the folder where you want to create your project and open cmd prompt and enter the commands given below for respective archetype.
simple-content-package-archetype: mvn archetype:generate -DarchetypeGroupId=com.day.jcr.vault -DarchetypeArtifactId=simple-content-package-archetype -DarchetypeVersion=1.0.2 -DarchetypeRepository=adobe-public-releases -DarchetypeVersion=1.0.2 -DgroupId=my-group-id -DartifactId=myproject -Dversion=1.0-SNAPSHOT -Dpackage=com.mycompany.myproject -DappsFolderName=myproject -DcqVersion=”5.6.1″ -DartifactName=”My Project” -DpackageGroup=”My Company”
simple-content-package-with-embedded-archetype: mvn archetype:generate -DarchetypeGroupId=com.day.jcr.vault -DarchetypeArtifactId=simple-content-package-with-embedded-archetype -DarchetypeVersion=1.0.2 -DarchetypeRepository=adobe-public-releases -DarchetypeVersion=1.0.2 -DgroupId=my-group-id -DartifactId=myproject -Dversion=1.0-SNAPSHOT -Dpackage=com.mycompany.myproject -DappsFolderName=myproject -DcqVersion=”5.6.1″ -DartifactName=”My Project” -DpackageGroup=”My Company”
multimodule-content-package-archetype: mvn archetype:generate -DarchetypeGroupId=com.day.jcr.vault -DarchetypeArtifactId=multimodule-content-package-archetype -DarchetypeVersion=1.0.2 -DarchetypeRepository=adobe-public-releases -DarchetypeVersion=1.0.2 -DgroupId=my-group-id -DartifactId=myproject -Dversion=1.0-SNAPSHOT -Dpackage=com.mycompany.myproject -DappsFolderName=myproject -DartifactName=”My Project” -DcqVersion=”5.6.1″ -DpackageGroup=”My Company”
General procedure for creating project
Note: The procedure is shown for multimodule project creation as it is widely used one. The console text and project structure screenshot corresponds to multimodule project creation.
Entering command in cmd will ask you for the confirmation of the properties.
Press ‘y’ and ‘enter’.
Once build succeeds you will get a build success message.
You can change the parameters of the command to change the name of the project, groupID, etc…
Project structure created will look something like this
Since, simple-content-package-with-embedded-archetype project creation is confusing, adding the cmd screenshot for the same below.
Developed Project Structures
1. simple-content-package-archetype:
2. simple-content-package-with-embedded-archetype
3. multimodule-content-package-archetype
No comments:
Post a Comment
If you have any doubts or questions, please let us know.