Getting Started

Let’s walk through the steps required to use Javascript in your MicroEJ application:

mmm init -Dskeleton.org=com.is2t.easyant.skeletons -Dskeleton.module=firmware-singleapp -Dskeleton.rev=1.1.12 -Dproject.org=com.mycompany -Dproject.module=myproject -Dproject.rev=1.0.0 -Dskeleton.target.dir=myproject

Adapt the properties values to your need. See the MMM CLI init command documentation for more details.

Javascript is supported in the following Module Natures page: - Add-On Library, - Standalone Application, - Sandboxed Application.

  • add the js dependency in the build file:

implementation("com.microej.library.runtime:js:0.13.0")
  • add the following lines in your application main class:

import com.microej.js.JsErrorWrapper;
import com.microej.js.JsCode;
import com.microej.js.JsRuntime;

...

JsCode.initJs();
JsRuntime.ENGINE.runOneJob();
JsRuntime.stop();
  • create a file named hello.js in the folder src/main/js with the following content:

function hello() {
    var message = "MicroEJ Javascript application!";
    print("My first", message);
}

hello()
  • follow the steps described in the run command documentation

  • in a terminal, go to the folder containing the module.ivy file and build the project with the command:

mmm build

You should see the following message at the end of the build:

BUILD SUCCESSFUL

Total time: 20 seconds
  • now that your application is built, you can run it in the simulator with the command:

mmm run

You should see the following output:

My first  MicroEJ Javascript application!

You can now go further by exploring the capabilities of the MicroEJ Javascript engine and discovering the commands available in the CLI.