Setup development environment

October 12th, 2020


This is the 1st article of a Build Java Module for Mango series. You can check all the articles by clicking here

Requirements

You need to have the latest stable version of JDK and Maven installed:

Project setup

The first thing we need to do is to configure our IDE to be able to build our Mango module. In my case, I’m going to use IntelliJ IDEA (community edition). Follow the next steps:

<project xmlns="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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.infiniteautomation.mango</groupId>
    <artifactId>mango-root</artifactId>
    <version>4.0.0-SNAPSHOT</version>
    <name>Modules and core</name>
    <packaging>pom</packaging>
    <organization>
        <name>Radix IoT</name>
        <url>http://www.RadixIoT.com/</url>
    </organization>
    <modules>
        <module>./ma-core-public</module>
        <module>./ma-modules-public</module>
        <module>./ma-dashboards</module>
    </modules>
</project>

This file is really helpful when you want to include modules which are located in a different directory.

  • Open the pom.xml file as a maven project from the IDE, this will load all the modules that we previously cloned.
  • Create a settings.xml file, and set your Mango root directory (this is the directory’s path of the Mango that we previously downloaded).
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          https://maven.apache.org/xsd/settings-1.0.0.xsd">
    <profiles>
      <profile>
        <id>set-ma-home</id>
        <properties>
        <MA_HOME>/{YOUR MANGO ROOT DIRECTORY}/mango</MA_HOME>
        </properties>
      </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>set-ma-home</activeProfile>
    </activeProfiles>
</settings>
  • Create an energyMetering directory.
  • Create a pom.xml file into the energyMetering directory with the next content:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>modules-parent</artifactId>
        <groupId>com.infiniteautomation.mango</groupId>
        <version>4.0.0-SNAPSHOT</version>
        <relativePath>../ma-core-public/Modules/pom.xml</relativePath>
    </parent>
    <artifactId>EnergyMetering</artifactId>
    <version>4.0.0-SNAPSHOT</version>
    <name>EnergyMetering</name>
    <build>
        <plugins>
            <plugin>
                <groupId>eu.somatik.serviceloader-maven-plugin</groupId>
                <artifactId>serviceloader-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
            </plugin>
<!--            <plugin>-->
<!--                <groupId>com.github.eirslett</groupId>-->
<!--                <artifactId>frontend-maven-plugin</artifactId>-->
<!--            </plugin>-->
        </plugins>
    </build>
    <description>Energy Metering</description>
</project>

We use as the parent module the ma-core-public. For now we will comment com.github.eirslett. This we will be used when we add the frontend.

  • In the IDE, right click on energyMetering/pom.xml and select Add as Maven project.
  • Go to Preferences > Build, Execution, Deployment > Build Tools > Maven and set in the User settings file the setting.xml file path.
  • Go to Run > Edit Configurations… and add a new Maven configuration like this:

Debug configuration

This configuration will help us to build our module later directly from the IDE:

Run EnergyMetering

Now, click on Run ‘EnergyMetering’, and a Run panel will be opened with the build process. If everything went good, you should see something like this:

Build Success

And you should see a EnergyMetering-4.0.0-SNAPSHOT.zip in the <YOUR MANGO ROOT>/web/modules. There are a lot of things that we need to do before we see something in the Mango. But, we have our development platform ready!

Copyright © 2020 Radix IoT, LLC.