Magnolia 5.7 reached extended end of life on May 31, 2022. Support for this branch is limited, see End-of-life policy. Please note that to cover the extra maintenance effort, this EEoL period is a paid extension in the life of the branch. Customers who opt for the extended maintenance will need a new license key to run future versions of Magnolia 5.7. If you have any questions or to subscribe to the extended maintenance, please get in touch with your local contact at Magnolia.
A bundle is a package consisting of a Magnolia webapp and a selection of modules. Each bundle has a particular purpose such as demonstration or production use. In this tutorial you create your own bundle. Select only the modules the project needs, not more. A small purpose-built bundle is easy to understand and fast to build and deploy. Maven handles the dependencies between modules.
Bundles provided by Magnolia
Magnolia provides a number of ready-made bundles. For more information please read bundles and webapps.
Tools
In this tutorial we use:
- Maven: You should be familiar with the Maven dependency mechanism. The same concept applies to other dependency management and build tools such as Ant+Ivy or Gradle. See Maven setup if you are new to Maven or want to install it in order get access to Magnolia resources from Magnolia Nexus.
- IDE: The examples and screenshots are from IntelliJ IDEA but any Java IDE such as Eclipse or Netbeans works. If you work with a different tool and would like to contribute steps, leave a comment.
- Terminal or command line: Some commands in this tutorial are Mac OS X specific. Replace them with equivalent commands on your operating system.
Create an empty project
Open a terminal and go to a directory where you keep your Magnolia projects.
cd ~/development/magnolia
- Generate a new project from a Maven archetype:
mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeCatalog=https://nexus.magnolia-cms.com/content/groups/public/
- Choose the magnolia-project-archetype from the options Maven presents.
- Provide the project information. Press ENTER to accept the default.
- Version: Choose the latest version provided.
- Group ID:
example.com
or a group ID that reflects your company. - Artifact ID:
example-project
or an artifact ID that reflects your project. - Version:
1.0-SNAPSHOT
- Package:
example.com
. Maven proposes a package name based on the group ID. You can change it later in configuration. - magnolia-bundle-version: Find the latest Magnolia bundle version in Releases.
- Project name:
example-com
. Maven proposes a package name based on the group ID. You can change it later in configuration.
Verify your input and accept with Y:
Confirm properties configuration: groupId: com.example artifactId: example-project version: 1.0-SNAPSHOT package: com.example magnolia-bundle-version: 5.6.6 project-name: example-project
Maven creates an empty project structure in the current directory.
Project structure:
example-project
: Parent project.example-project-webapp
: Your custom bundle as a child Maven project. Here you find a typical Magnolia project folder structure.pom.xml
: Webapp project POM.src
: Java source code and project configuration
pom.xml
: Parent POM.
Build the project
Go to the project folder that Maven created:
cd example-project
Build the project:
mvn clean install
Run the project
Open the project in your IDE. These instructions are for IntelliJ IDEA. Adapt for other IDEs.
- In IDEA, go to File > Import project > Browse to the parent project
pom.xml
. - Go to Run > Edit Configurations > + > Tomcat Server > Local.
- Go to the Deployment tab and add an artifact
example-project-webapp:war exploded
. - Set Application Context to root (/). You can deploy the application to a different context if you like.
- Start the project.
The Tomcat application server starts and deploys the Magnolia project. If your IDE does not open a Web browser automatically, go to
http://localhost:8080/
.
Install Magnolia and log in
Start Magnolia installation.
Note: The screenshot above is outdated showing installation tasks when using Magnolia 5.3.6. We recommend always using the latest stable Magnolia version when creating a new custom bundle.
Log in:
- Username:
superuser
- Password:
superuser
You are now running a basic Magnolia project with an empty webapp.
Add modules
If the magnolia-empty-webapp
runs without errors, the project is ready to add modules according to your requirements. In this example we add the REST modules.
Look at the parent project pom.xml file in example-project/pom.xml
. It uses Maven's dependency management mechanism to import dependencies from the ce-bundle. (Search for the commented note "Importing dependencyManagement of CE bundle".)
When you add modules to your example-project-webapp
you don't have to specify their versions. Version numbers are inherited from the dependency-management
section of the ce-bundle. You only need to specify the version in example-project/example-project-webapp/pom.xml
- if you want to override the versions defined in the dependency management of the ce-bundle.
As an example, add the REST modules to your project. Add the following code in the dependencies
section of the webapp pom in example-project/example-project-webapp/pom.xml
:
<dependency> <groupId>info.magnolia.rest</groupId> <artifactId>magnolia-rest-integration</artifactId> </dependency> <dependency> <groupId>info.magnolia.rest</groupId> <artifactId>magnolia-rest-services</artifactId> </dependency> <dependency> <groupId>info.magnolia.rest</groupId> <artifactId>magnolia-rest-content-delivery</artifactId> </dependency>
IntelliJ IDEA displays a notification when you modify a POM file. It prompts you to “Import Changes” or “Enable Auto-Import”. Enabling auto-import works quite well but can be resource intensive if you modify POM files heavily. In this example you can enable auto-import. If you choose not to, remember to click “Import Changes” at least once before starting up the server.
Restart your server for the new modules to be picked up. Magnolia asks you to install the REST modules. After installation you can find a new app in the Dev group and you can start the REST Tools app.
Conclusion
In this tutorial you learned how to create a Magnolia project from a Maven archetype, built the project with Maven, and added custom modules. The project does not do much yet but you reached important goals already:
- You built your own project with Magnolia. You did not need to manually “drop a jar” in the Web application or modify a configuration file in the deployed webapp.
- The build is reproducible. You can check your files into a source control system. Based on the files your team mates or a continuous integration server can reproduce the build any time. They can also release your project.
Credits:
- Gregory Joseph: Don't Build Magnolia, Build Your Projects