Using Maven to create a webapp allows you to customize your webapp
through the POM files, which can be tracked with a
version control system
like Git. A tailored webapp makes
building and deploying faster and has a positive impact on the
performance of your instances.
In the steps below, you use the magnolia-dx-core-webapp as the base
and exclude the following two modules from it:
In the next two steps, you edit the two pom.xml files.
Editing the parent POM
In the dependencyManagement section, remove the Option A.
Uncomment the Option B.
In the repositories section, uncomment the repository with the id
magnolia.enterprise.releases.
The resultant parent POM:
custom-dx-core-project/pom.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?><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>com.example</groupId><artifactId>custom-dx-core-project</artifactId><name>custom-dx-core-project (parent pom)</name><version>1.0-SNAPSHOT</version><packaging>pom</packaging><properties><magnoliaBundleVersion>6.2</magnoliaBundleVersion><javaVersion>1.8</javaVersion></properties><!-- Fill the following in, so you can use the release plugin --><scm><connection/><developerConnection/><url/></scm><dependencyManagement><dependencies><!-- Option B --><!-- If you want to use the DX CORE. --><dependency><groupId>info.magnolia.dx</groupId><artifactId>magnolia-dx-core-parent</artifactId><version>${magnoliaBundleVersion}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><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 your module descriptors --><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.enterprise.releases</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><modules><module>custom-dx-core-project-webapp</module></modules></project>Copy
Editing the webapp POM
In the webapp POM file, modify the dependencies section.
<?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><parent><groupId>com.example</groupId><artifactId>custom-dx-core-project</artifactId><version>1.0-SNAPSHOT</version><relativePath>../pom.xml</relativePath></parent><artifactId>custom-dx-core-project-webapp</artifactId><name>custom-dx-core-project: webapp</name><packaging>war</packaging><dependencies><!--
Add your project specific dependencies here:
A custom webapp typically is based on a magnolia webapp. The most simple and reduced bundle to start with is the "magnolia-empty-webapp" (see "option i" below).
=> Please just use one of the four below listed options!
Make sure to use the appropriate option (A or B) in the parent pom
--><!-- option iii - magnolia-dx-core-webapp --><!-- Dependencies versions are already imported by parent pom. Requires "Option B" in the parent pom. --><dependency><groupId>info.magnolia.dx</groupId><artifactId>magnolia-dx-core-webapp</artifactId><type>war</type></dependency><dependency><groupId>info.magnolia.dx</groupId><artifactId>magnolia-dx-core-webapp</artifactId><type>pom</type><exclusions><exclusion><groupId>info.magnolia.translation</groupId><artifactId>magnolia-content-translation</artifactId></exclusion><exclusion><groupId>info.magnolia.translation</groupId><artifactId>magnolia-content-translation-pages-integration-app</artifactId></exclusion><exclusion><artifactId>info.magnolia.marketingtags</artifactId><groupId>magnolia-marketing-tags</groupId></exclusion></exclusions></dependency></dependencies><build><plugins><plugin><artifactId>maven-war-plugin</artifactId><configuration><!-- exclude jars copied "physically" from the webapp overlay - so we only get those resolved by Maven's dependency management --><dependentWarExcludes>WEB-INF/lib/*.jar</dependentWarExcludes></configuration></plugin></plugins></build></project>Copy
When excluding a module from a webapp, you must check whether other
modules, which are still part of the webapp, do not have runtime
dependencies to the module you exclude. At the latest, you can discover
any unsatisfied runtime dependency during the startup of your Magnolia
webapp. Runtime dependencies are defined in the
Magnolia Module descriptors.
Want to add your own dependencies?
Suppose you want to add, for example, the E-commerce dependencies outlined on this page: E-commerce Module. In that case, you must check whether the Magnolia bundle version is suitable for them. For instance, E-commerce 1.3.1 requires at least Magnolia 6.2.7; however, this tutorial uses the Magnolida bundle 6.2 when creating the webapp archetype. This can be resolved by increasing the Magnolia bundle version magnoliaBundleVersion in the parent POM file or decreasing the E-commerce version dependencies in the webapp POM file.
If you cannot find the necessary dependency information on a module page, please inspect the build log for missing dependencies when building the project with Maven.
Adding further resources
The skeleton produced by the Maven archetype has several folders which
we have not used so far. This concerns especially the src folder in
the webapp subdirectory. In the context of this tutorial page it is
the custom-dx-core-project/custom-dx-core-project-webapp/src folder.
This folder has the following subfolders:
src/
└── main
└── webapp
├── WEB-INF
│ ├── bootstrap
│ │ ├── author
│ │ ├── common
│ │ └── public
│ └── config
│ └── default
└── docroot
Copy
If you leave these subfolders empty, Maven takes the content from the
imported webapp, that is the magnolia-dx-core-webapp.
The magnolia-dx-core-webapp inherits from the
magnolia-community-webapp.
Customizing the magnolia.properties file
In this step, you add the (default) magnolia.properties file and
customize the magnolia.resources.dir property in it.
What is magnolia.resources.dir?
magnolia.resources.dir is a property defining the directory from which
resources are loaded in a Magnolia instance.
This directory is used for file-based resources such as light modules
and for overriding classpath resources. The property is configured in
WEB-INF/config/default/magnolia.properties and its default value is
$magnolia.home/modules. To see the current value of the property, go
to the Config Info tab in the
About Magnolia app.
You can use
symbolic links (symlinks or
soft links) in the resources directory to include light modules located
elsewhere on your system.
Set the magnolia.resources.filesystem.observation.excludedDirectories
property to exclude directories from being observed for changes. (See the table in the Configuration management: Defining properties section.)
Create the magnolia.properties file in the following folder:
custom-dx-core-project/custom-dx-core-project-webapp/src/main/webapp/WEB-INF/config/default/.