Monday, May 18, 2015

Setting up leJOS-0.9 with Java 8

The premier implementation of Java for the various Lego Mindstorms robots is LeJOS.  For the Mindstorms EV3, Oracle has facilitated the LeJOS implementation by providing pre-bundled Java microeditions.  Java version 7 update 60 is ready-to-go as part of the leJOS setup.  But the Oracle download page includes the following cryptic message regarding the use of Java 8:
Java SE Embedded 8 enables developers to create customized JREs using the JRECreate tool. Starting with Java SE Embedded 8, individual JRE downloads for embedded platforms are no longer provided. To get started, download the bundle below and follow instructions to create a JRE that suits your application's needs.
Of course, for a leJOS developer who would like to use Java 8, this is not entirely helpful.  Following some hints on the LeJOS EV3 forums, I was able to figure out how to do this.  This sequence of shell commands should work on any Unix/Linux platform.  (I am using a Mac.)  I would imagine it would also work on Windows if gzip and tar programs are installed.

gunzip ejdk-8-fcs-b132-linux-arm-sflt-03_mar_2014.gz
tar xvf ejdk-8-fcs-b132-linux-arm-sflt-03_mar_2014
cd ejdk1.8.0/bin
export JAVA_HOME=/usr
./ --dest ../../ejre-8u1-linux-arm-15_may_2015 --profile compact2 --vm client
cd ../..
tar cvf ejre-8u1-linux-arm-15_may_2015.tar ejre-8u1-linux-arm-15_may_2015
gzip ejre-8u1-linux-arm-15_may_2015.tar

Having created the Java 8 configuration file ejre-8u1-linux-arm-15_may_2015.tar.gz, simply specify it when creating the SD card, and everything should work fine.

The English-language summary of the above command sequence is as follows:

  • Uncompress the archive using gunzip.
  • Extract the contents of the archive using tar.
  • Go to the subdirectory containing jrecreate.
    • On Windows, you would want to use jrecreate.bat rather than
  • Set up the JAVA_HOME environment variable if it is not already set.
  • Run jrecreate with the following options:
    • --dest specifies where the configured implementation will be placed.  
    • --profile needs to be compact2 to ensure certain features LeJOS requires are present.
    • --vm needs to be client for the same basic reason.
  • Use tar to repack the archive.
  • Use gzip to compress the archive.
  • I made up a filename that seems to be compatible with what LeJOS will be looking for.
In my next post, I'll give an example that illustrates some of the capabilities of Java 8 in this environment.


  1. Did you experiment with newer/other releases? I found e.g. ejdk-8u33-fcs-linux-arm-sflt.tar.gz As this is released for EV3 by Oracle, I expect no problems. When I click on "other releases", I find e.g. ejdk-8u65-linux-arm-sflt.tar.gz

    1. I have not as of yet. As Java (and leJOS) evolve, I probably will.