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
./jrecreate.sh --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 jrecreate.sh.
  • 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.

6 comments:

  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

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

      Delete
  2. Hi Gabriel,

    This is amazing blog. thank you very much for a detailed step. I want to install Java 8 on leJOS-0.9.

    Below are steps i followed.
    1. Downloaded JRE file from below location (Oracle Java SE Embedded version 8 Update 33 - ejdk-8u33-fcs-linux-arm-sflt.tar.gz)
    http://www.oracle.com/technetwork/java/embedded/embedded-se/downloads/legomindstormev3-2200042.html

    2. I did format SD card and added JRE file, on loading the file on EV3 i received error JRE file Missing.

    3. I followed your block and used ejdk-8u33-fcs-linux-arm-sflt.tar.gz as reference and create a new JRE file ejre-8u1-linux-arm-15_may_2015

    4. Loaded file on SD card and EV3 now I am getting different error Failed to Extract JRE file. Can you help me understand what is missing here?

    ReplyDelete
  3. Ciao Gabriel,

    i figured to get Java 8 (b132) up and running on my EV3 brick some weeks ago. Everythings fine.

    Yesterday I started playing with the ColorSensor thingy (using Aplus OOP Layer http://www.aplu.ch ) which seems to depend on java.awt.Color - which - in compact2 - just isnt there (at least it fails with a ClassNotFoundEx and there is nothing awt-ish in rt.jar).

    So I take it, the compact2 profile is fine without using the OOP layer?

    I am interested in your opinion - should I try reinstalling Java8 on the brick with full VM or am I just missing something here?


    Greets,
    Sandro

    ReplyDelete
    Replies
    1. Replying your own self is weird, I know.

      Update:
      I rebuilt the erje w/out any compact and --vm client. tar.gz is now about 34mb and everything (including ColorSensor) works fine.

      Still, I'm interested in any opinions on this!


      -Sandro

      Delete
  4. Fyi, if you want to enable remote debuging through jdwp, you need to add the --debug flag when executing ./jrecreate.sh

    ReplyDelete