Skip to content

Using Speedment with the Module System

Mislav Milicevic edited this page Nov 8, 2019 · 5 revisions

As of version 3.2.0, Speedment fully supports the Module System (JPMS) that was introduces as part of Java 9. This guide describes how to enable JPMS in new or existing Speedment projects.

Note: This is not a JPMS tutorial - prior knowledge on the topic is expected.

New Projects

If you're starting fresh, most of the heavy lifting is done for you. To enable JPMS support in new Speedment projects, head over to our Initializer and fill in your project details. Make sure that the selected Java version is Java 11, that the Java Modules option is enabled and click the Download button.

By clicking the Download button, you will receive a ZIP archive, which contains all the necessary files that are needed to start using Speedment with JPMS.

Existing Projects

If you want to enable JPMS support for an existing Speedment project, there are a couple of additions that have to be made in order to do so.

Let's start with the changes that need to be made in your pom.xml file.

  1. If you're using a Speedment version prior to 3.2.0, you must update your Speedment dependencies to version 3.2.0 or greater.
  2. You must add the Maven Compiler Plugin:
<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
</plugin>

In order to actually use JPMS in your project, you must create a module-info.java file in your source root (typically src/main/java). Once you create the module-info.java file, add the following snippet to it:

module mymodule {
    /*
    * Base Speedment Runtime module
    */
    requires com.speedment.runtime.application;
    /*
    * Depending on which database connector you're using, this import will change.
    * For example, if you're using MariaDB, you will import `com.speedment.runtime.connector.mariadb`
    */
    requires com.speedment.runtime.connector.mysql;
    /*
    * If your project doesn't use joins, you can remove this
    */
    requires com.speedment.runtime.join;
}

This is a bare-bones Speedment setup for JPMS. Depending on how you've configured your Speedment project in the beginning, i.e. enabled DataStore or enabled a plugin, you might need to include additional modules:

module mymodule {
    /*
    * Base Speedment Runtime module
    */
    requires com.speedment.runtime.application;
    /*
    * Depending on which database connector you're using, this import will change.
    * For example, if you're using MariaDB, you will import `com.speedment.runtime.connector.mariadb`
    */
    requires com.speedment.runtime.connector.mysql;
    /*
    * If your project doesn't use joins, you can remove this
    */
    requires com.speedment.runtime.join;

    /*
    * If you have DataStore enabled
    */
    requires com.speedment.enterprise.datastore.runtime;
    /*
    * If you have Enum plugin enabled
    */
    requires com.speedment.enterprise.plugins.enums;
    /*
    * If you have JSON plugin enabled
    */
    requires com.speedment.enterprise.plugins.json;
    /*
    * If you have Spring plugin enabled, add all modules below
    */
    requires com.speedment.enterprise.plugins.spring.runtime;
    requires spring.boot;
    requires spring.web;
    
    requires java.annotation;
    requires spring.webmvc;
    requires spring.beans;
    requires spring.context;
    requires spring.core;
    requires spring.boot.autoconfigure;
}