This page explains how to use Magnolia-specific Maven archetypes to jumpstart development of Magnolia Maven modules and projects.

If you want to generate a Magnolia Cloud project archetype to create a custom cloud bundle, see Creating and deploying custom cloud bundles.

Requirements

You need Maven to generate Magnolia project archetypes. To setup Maven, follow the procedure described on our Maven setup page. During the setup, the settings.xml file is created.

Depending on whether you are a user of the Community Edition or DX Core, check that the file contains the following snippet. If it does not, add it to the file, before the profiles section.

  <mirrors>
    <mirror>
      <id>magnolia.nexus.public</id>
      <url>https://nexus.magnolia-cms.com/content/groups/public</url>
      <mirrorOf>archetype</mirrorOf>
    </mirror>
  </mirrors>
  <mirrors>
    <mirror>
      <id>magnolia.nexus.enterprise</id>
      <url>https://nexus.magnolia-cms.com/content/groups/enterprise/</url>
      <mirrorOf>archetype</mirrorOf>
    </mirror>
  </mirrors> 

The Archetype plugin

The Maven Archetype Plugin allows you to create a Maven project from an archetype – an existing template (a skeleton of files and directories).

The base plugin command is mvn archetype:generate.

  • For an overview of the parameters it accepts, see the archetype:generate page on the Apache Maven Project website.
  • For details on how the command works and how to use the interactive mode, see the Usage page on the site.

Option A

If you already know which Magnolia archetype you want to generate, the fastest way is to supply the archetype's Maven coordinates (GAV) to the command line. For example:

mvn archetype:generate -DarchetypeGroupId=info.magnolia.maven.archetypes -DarchetypeArtifactId=magnolia-project-archetype -DarchetypeVersion=RELEASE

(warning) If you omit the archetypeVersion, the plugin automatically picks the oldest version.

Option B

By default, the archetype plugin collects a list of all possible archetypes, including those found at Maven Central. The list can be very long and it may take some time to generate it.  To reduce the list only to available Magnolia archetypes, use the plugin command with the following filter option:

mvn archetype:generate -Dfilter=info.magnolia.maven.archetypes:magnolia

(lightbulb) If you need to interrupt the command, press CTRL + C.

Which Magnolia archetype to use?

Magnolia provides the following archetypes:

  1. The magnolia-project-archetype, generates a Magnolia project with a parent POM and a Magnolia webapp.
  2. The magnolia-module-archetype, generates a Magnolia Maven module. For details, please refer to the Modules page.
  3. The magnolia-blossom-module-archetype, generates a Magnolia Maven module with support for the Blossom module.

Before generating a project, the archetypes ask you to supply values for the following parameters:

Required parametersExample valueExplanation
Maven groupId com.example

Typically, it reflects the name or domain of your organization.

Maven artifactIdcustom-projectProject-specific identifier.
Maven version1.0-SNAPSHOTProject version. When creating a new project, use the value suggested by Maven, for example 1.0-SNAPSHOT.
package com.example Package name for Java classes reflecting both your organization and the specific project.
magnolia-bundle-version6.1

Magnolia version to be used in your custom project.

project-nameCustom Project

A human-readable version of the artifactId, Title case and spaces are allowed.

Additional parameters
module-class-nameFoobarModule The Java class name of the generated module class (for module archetypes only).
blossom-version3.2.1 The version of the Magnolia Blossom module (for the blossom module archetype only).

Discontinued archetypes

As of version 1.2.5, the following archetypes have been discontinued. Older versions may still appear if you use the filter option.

  • The magnolia-forge-module-archetype, used to create a Magnolia module for the former Magnolia Forge (moved to GitHub: Magnolia Forge).
  • The magnolia-theme-archetype, used to create an STK (deprecated) theme module.

Which archetype version should I use?

Use the latest archetype release: 

Error rendering macro 'artifact-resource-macro'

com.sun.jersey.api.client.ClientHandlerException: java.net.NoRouteToHostException: No route to host (Host unreachable)

. Exceptionally, Enterprise Edition projects for use with Magnolia 5.7 or lower should be generated with version 1.2.4.

Generated skeletons

A creation of a project typically results in the following skeleton, with a few more files created in src/main/webapp. For details, see Creating a custom webapp with Maven.

custom-project/
├── custom-project-webapp
│   ├── pom.xml
│   └── src
│       └── main
│           └── webapp
└── pom.xml

On the other hand, if you create a module, the skeleton will have a simpler structure (no multi-module Maven reactor), with a pre-generated Magnolia module descriptor and Java module class. See also Module structure.

custom-module/
├── pom.xml
└── src
    ├── main
    │   ├── java
    │   └── resources
    │       └── META-INF
    │           └── magnolia
    │               └── custom-module.xml
    └── test
#trackbackRdf ($trackbackUtils.getContentIdentifier($page) $page.title $trackbackUtils.getPingUrl($page))