Run a simulation with Eclipse MOSAIC as Developer

On this page we want to discuss how to run Eclipse MOSAIC directly from source code, and with an IDE. This is only relevant if you want to implement changes to MOSAIC itself. If you simply want to run different simulations, please skip this page.

Prerequisites

You have to install the same requirements as for the bundeled MOSAIC version, namely the Java SDK and Eclipse SUMO. Additionally you also need to install Apache Maven.

Get the code

Please find the MOSAIC code in the Github repository here. Let’s say you would like to contribute your changes, so you fork the repository first, and read guideline how to contribute.

git clone git@github.com:<github-username>/mosaic.git eclipse-mosaic
cd eclipse-mosaic
git remote add upstream git@github.com:eclipse/mosaic.git # when using ssh
mvn clean install

From the Command-Line-Interface

The entry class MosaicStarter has a lot of dependencies which need to be referenced during startup, so we recommend that you use the package functionality of maven and then run the bundle. Everything else would be overly complicated. Also, we don’t build “fat jars” so you won’t be able to run any jar directly. The following is almost the same procedure as presented in the non-developer guides, just that you build the bundle locally.

  • Run mvn clean install
  • Unzip one of the bundle/target/eclipse-mosaic-24.1-SNAPSHOT.* archives to a destination of your choice
  • Run the mosaic.sh/bat files, which will do all the magic for you (have a look inside if you ask yourself if there’s a more direct way to start from console).

Use IntelliJ IDEA

  • Start IntelliJ IDEA and choose Open or Import (see figure 1).
  • Choose the cloned eclipse-mosaic repository
  • For IntelliJ there’s already a pre-defined run configuration in the repo which should work right away when you run it (see figure 2).

Good to know:

  • When changing any pom.xml you need to: Rightclick on root-module > Maven > Reload project
  • When making changes to runtime.json | logback.xml | hosts.json you need to re-run mvn validate, in order to copy them into the target folder.

Open the project
Run MosaicStarter

File locations

Given that you execute the code from source, some important file locations change:

Bundled From Source
<mosaic-root>/scenarios <mosaic-root>/bundle/src/assembly/resources/scenarios
<mosaic-root>/etc <mosaic-root>/rti/mosaic-starter/target/classes/etc
<mosaic-root>/logs <mosaic-root>/rti/mosaic-starter/logs