Open a shell and change to the directory where you want to create the
new module.
cd ~/dev/repo/magnolia/chms-zeugs
Copy
There are several ways and possible parameters when calling the Maven
archetype command. For further details, refer to
How to use
Magnolia Maven archetypes. We assume you are using the command in the
same way as shown here:
After calling the archetype plugin command, you enter the interactive
mode. The plugin prompts you to provide input for some parameters. For
the given example here, we use these parameter values:
Parameter
Example value
Explanation
Maven groupId
info.magnolia.documentation
Typically reflects the
name or domain of your company or projects
Maven artifactId
my-ui-components
Project-specific identifier
Maven artifact version
1.0-SNAPSHOT
Project version: when
creating a new project, use the value suggested (1.0-SNAPSHOT).
package
info.magnolia.documentation.newui
Package name for Java
classes reflecting both your company (or domain) and the specific
project
magnolia-bundle-version
6.2
The Magnolia version from which your
custom project inherits
Module class name
MyUiModule
The java class name of the
autogenerated module class
project-name
my-ui-components
Project name
After you have provided all the data, the plugin lists all your input
and asks for confirmation. Press ENTER to confirm and wait for the
plugin to generate the skeleton of your archetype. The command should
finish with a SUCCESS message in the console.
Lines 2–ff: src/main/java is where to add Java source
classes in a Maven module.
In the java folder, the archetype has created folders to reflect the
Java package info.magnolia.documentation.newui as specified while
running the archetype create command.
Module class (info.magnolia.documentation.newui.MyUiModule)
Module version handler class
(info.magnolia.documentation.newui.setup.MyUiModuleVersionHandler)
Line 13:
XML-based
module descriptor
(src/main/resources/META-INF/magnolia/my-ui-components.xml)
You will edit the file later to define module runtime dependencies and
to register components.
Line 18: i18n
message bundle
(src/main/resources/my-ui-components/i18n/module-my-ui-components-messages_en.properties)
The POM file
POM stands for project object model. It is an XML representation of a
Maven project held in a file named pom.xml (see
https://maven.apache.org/pom.html). The file defines dependency
management, dependencies, resources, repositories and the build.
Here is pom.xml as generated by the Maven archetype:
my-ui-components/pom.xml
<?xml version="1.0" encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>info.magnolia.documentation</groupId><artifactId>my-ui-components</artifactId><version>1.0-SNAPSHOT</version><packaging>jar</packaging><name>my-ui-components Magnolia Module</name><!--
<description>Please uncomment and fill in ...</description>
--><properties><magnoliaBundleVersion>6.3.0-SNAPSHOT</magnoliaBundleVersion><javaVersion>{base-java-version}</javaVersion></properties><dependencyManagement><dependencies><dependency><groupId>info.magnolia.bundle</groupId><artifactId>magnolia-bundle-parent</artifactId><version>${magnoliaBundleVersion}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><dependency><groupId>info.magnolia</groupId><artifactId>magnolia-core</artifactId></dependency><!-- TEST --><dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.7.0</version><configuration><source>${javaVersion}</source><target>${javaVersion}</target></configuration></plugin></plugins><!-- default resources configuration which will filter the module descriptor --><resources><resource><directory>src/main/resources</directory><includes><include>**/*</include></includes></resource><resource><filtering>true</filtering><directory>src/main/resources</directory><includes><include>META-INF/magnolia/*</include></includes></resource></resources></build><repositories><repository><id>magnolia.public</id><url>https://nexus.magnolia-cms.com/repository/public</url><snapshots><enabled>true</enabled></snapshots></repository><!-- IF YOU NEED MODULES FROM THE ENTERPRISE VERSION, UNCOMMENT THE FOLLOWING REPOSITORY --><!--
<repository>
<id>magnolia.nexus.enterprise</id>
<url>https://nexus.magnolia-cms.com/repository/enterprise</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
--><repository><id>vaadin-addons</id><url>https://maven.vaadin.com/vaadin-addons</url></repository></repositories></project>Copy
When adding a Maven dependency of the Magnolia Maven module, it is good
practice to add that dependency in the Magnolia module descriptor too.
The Magnolia Maven archetype creates such dependencies for the Magnolia
core module by default.
In the next sections, you will add—as an example—another dependency for
the Magnolia UI core framework for building UIs. If you want to create
a custom module with custom UI components, adding the UI core
framework is a good idea. For other use cases, you may want to add
other dependencies.
Module identifiers
The identifier(s) to specify a Maven module dependency in the POM file
and a Magnolia module in the Magnolia module descriptor are not the same
(but may be similar).
groupId
artifactId
Module name
Notes
info.magnolia
magnolia-core
core
Magnolia main core module.
info.magnolia.ui
magnolia-ui-framework
ui-framework-core
Magnolia UI core framework for building UIs.
Compile-time dependencies in the POM file
Among other things, the modules that the POM file defines compile time
dependencies to other Maven modules.
Now add the dependency for the magnolia UI framework (core) module.
In the snippet above, the dependency for junit has also been removed.
Generally, you should add test classes to your modules. In the context
of this tutorial, anything related to tests is not covered to keep
things simple.
Runtime dependencies in the module descriptor
The module descriptor is the file that
makes a module a Magnolia module. In a Maven module, this is an
XML-based
module descriptor that must be located in the directory
src/main/resources/META-INF/magnolia.
This is how the module descriptor has been generated by the archetype:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE moduleSYSTEM"module.dtd" ><module><name>my-ui-components</name><displayName>${project.name}</displayName><description>${project.description}</description><class>info.magnolia.documentation.newui.MyUiModule</class><versionHandler>info.magnolia.documentation.newui.setup.MyUiModuleVersionHandler</versionHandler><version>${project.version}</version><!-- For more information on module descriptor configuration options --><!-- https://docs.magnolia-cms.com/product-docs/6.2/Modules/Module-descriptor/XML-based-module-descriptor.html --><dependencies><dependency><name>core</name><version>*</version></dependency><!-- Add other dependencies here, e.g the mte (magnolia templating essentials).
<dependency>
<name>mte</name>
<version>0.7/*</version>
</dependency>
--></dependencies></module>Copy
Now add the dependency for the magnolia UI framework (core) module.
For each module in the dependencies section, we specify a version. For
the given example, use 6.0/*. This means the module must be version
6.0 or higher.
Your module descriptor file should now look like this:
The custom Magnolia Maven module that you have just created is the base
for adding Java classes (e.g. for custom UI components).
Git
You can get the source files for this custom Magnolia Maven module from our Git repository.
To get the same version of the module that you have created on this
page, you must check out the branch empty-custom-module.
cd /User/jdoe/magnolia/custom-modules
git clone https://bitbucket.org/magnolia-cms/my-ui-components.git
cd my-ui-components/
git checkout empty-custom-moduleCopy
Using the custom module on your Magnolia instance
To manage and maintain a custom Magnolia webapp, it is recommended you
use Maven.
Adding the custom module to a custom webapp via Maven
In this section, we assume that you have a custom Magnolia webapp that
you manage with Maven. Add the new custom module like this:
Edit the the parent POM. Add a new <dependency> entry to
<dependencies> within the <dependencyManagement> section.
Parent POM (fragment)
<dependencyManagement><dependencies><!-- you may have
many more sections here --><!-- new entry for the new module --><dependency><groupId>info.magnolia.documentation</groupId><artifactId>my-ui-components</artifactId><version>1.0-SNAPSHOT</version></dependency></dependencies></dependencyManagement>Copy
Edit the webapp POM. Add a new <dependency> entry to the
<dependencies> section.
Webapp POM (fragment)
<dependencies><!-- you may have many more sections here --><!-- new entry for the new module --><dependency><groupId>info.magnolia.documentation</groupId><artifactId>my-ui-components</artifactId></dependency></dependencies>Copy