Project on Magnolia CMS (Community Edition) from scratch

In this series of articles I’ll try to provide easy steps on how to create Magnolia CMS project with Community Edition version from scratch. I have installed Linux OS (Linux Mint) therefore all  my steps suitable for this OS, if your OS is different from mine you can simply change some paths within commands and all described steps will be valid for you.

Note: Before we start let’s open Magnolia CMS site and check required magnolia version (I’m referrer latest version for new projects). For current time this is 5.5.4

  1. Prerequisities
  2. Initial install
  3. Add module

Prerequisities

  1. First of all we should read about Magnolia CMS Certified Stack but in case of Linux/Windows we can omit it
  2. First of all we should install JDK 8 which we can download from the official Oracle site here.
  3. Then let’s install Maven version 3.2.3 or greater. It can be download from the official site here
  4. After Maven install we should update settings.xml (you can read more about it here) file which locates within Maven .m2 folder. It can be simply done with this command:
    mvn org.sonatype.plugins:nexus-m2settings-maven-plugin:1.6.8:download -DnexusUrl=https://nexus.magnolia-cms.com

Initial install

It’s time to install clean project on Magnolia CMS. Magnolia CMS project should be split on modules because it’s more easy to maintain and update such types of projects than monolithic one. With Maven archetype this is simple process which can be done in a couple of minutes. Let’s create wc project:

  1. open console and navigate to folder where you planned to located project:
    cd ~/dev
  2. Now lets create base Magnolia CMS project structure which will be based on modules. Initially we should create base pom module which will be parent for all other child modules in the project (from maven archetype plugin version 3 no more possible to specify archetype URL therefore we must specify version 2.4 directly):
    mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeCatalog=https://nexus.magnolia-cms.com/content/groups/public/
    Check steps which we will select during archetype install

    1. 2: https://nexus.magnolia-cms.com/content/groups/public/ -> info.magnolia.maven.archetypes:magnolia-project-archetype (An archetype to create a Magnolia project (a parent pom and a webapp))
    2. 5: 1.2.3-SNAPSHOT
    3. Define value for property 'groupId': : com.drfits.wc
      Define value for property 'artifactId': : wc
      Define value for property 'version': 1.0-SNAPSHOT: : 1.0.0-SNAPSHOT
      Define value for property 'package': com.drfits.wc: :
      Define value for property 'magnolia-version': : 5.5.4
      Define value for property 'project-name': wc: :
    4. Then confirm our selection by typing Y to the console.
  3. Now we should check that Magnolia project was created correctly and we can build it. So type to the console:
    mvn clean install
    And at the end of the build we should see “BUILD SUCCESS” and new file ~/dev/wc/wc-webapp/target/wc-webapp-1.0.0-SNAPSHOT.war . This is empty Magnolia CMS builded project which can be deployed to the supported servlet container and started.

Add module

After initial installation we can add our custom Magnolia module to the project (Magnolia CMS already has it’s own list of useful modules). Of cause we should separate our custom modules on UI modules (which defines light modules, CSS, JS, HTML templates and resources) and core modules which defines Java code for working with database, REST services and so on. Let’s create wc-core module. This can be done with provided Maven archetype:

  1. navigate within console to newly created directory (was created by steps from section Initial Install) ~/dev/wc and execute
    mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeCatalog=https://nexus.magnolia-cms.com/content/groups/public/
  2. Select steps as specified below:
    1. 3: https://nexus.magnolia-cms.com/content/groups/public/ -> info.magnolia.maven.archetypes:magnolia-module-archetype (An archetype to create basic Magnolia modules)
    2. Leave default number for Choose info.magnolia.maven.archetypes:magnolia-module-archetype version:
    3. Define value for property 'groupId': : com.drfits.wc
      Define value for property 'artifactId': : wc-core
      Define value for property 'version': 1.0-SNAPSHOT: : 1.0.0-SNAPSHOT
      Define value for property 'package': com.drfits.wc: : com.drfits.ws.core
      Define value for property 'magnolia-version': : 5.5.4
      Define value for property 'module-class-name': : WCCore
      Define value for property 'module-name': wc-core: :
    4. Then confirm our selection by typing Y to the console.
  3. Now open ~/dev/wc/wc-webapp/pom.xml and add dependency for wc-core module (in such way we should add other modules from which our project depends on):
    <dependency>
        <groupId>com.drfits.wc</groupId>
        <artifactId>wc-core</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </dependency>
  4. Open parent folder~/dev/wc in console and build our project:
    mvn clean install
  5. Now project output war file will have wc-core module (see maven console output below):
    [INFO] wc (parent pom) .................................... SUCCESS [ 0.224 s]
    [INFO] wc-core Magnolia Module ............................ SUCCESS [ 1.461 s]
    [INFO] wc: webapp ......................................... SUCCESS [ 7.370 s]
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS

Conclusion: In this article we’ve created new Magnolia CMS project wc with our custom module wc-core and include this module to the output war file~/dev/wc/wc-webapp/target/wc-webapp-1.0.0-SNAPSHOT.war.