nashorn Script Engine NullPointerException

Hello! Our team is trying to use Java 8s new nashorn engine on the new roboRIO, as it runs Java 8. However, we have encountered a NullPointerException every time we call new ScriptEngineManager().getEngineByName(“nashorn”). After a little debugging, we know it is the method getEngineByName that is returning null. We have tried rhino, simply getting every javascript engine, but we keep getting returned null. Is this a problem with the fact the roboRIO is running an embedded version of Java 8? Can another team try this?

Correct. You can take a look at the API’s included in our profile for the JRE here: http://www.oracle.com/technetwork/java/embedded/resources/tech/compact-profiles-overview-2157132.html. We use the compact 2 profile when creating the JRE. If you need to use Nashorn, you can create your own JRE and install it in /usr/local/frc/JRE. Take a look here for stuff about creating custom JREs: http://docs.oracle.com/javase/8/embedded/develop-apps-platforms/custom-jre.htm#A1161602. We use the following options when running JRECreate:


private static String] JRE_CREATE_COMMAND = {"java",
            "-jar",
            "", // This is the JRECreate jar location
            "--dest", "JRE", // This is the folder that you need to put in /usr/local/frc
            "--profile", "compact2",
            "--vm", "client",
            "--keep-debug-info",
            "--debug"
};

Thanks for the documentation I was able to create a jre haven’t tested it on the RoboRio yet.

I have another question. Is this legal for competition? I don’t want to ruin the spirit of FIRST

hears what I added

private static String] JRE_CREATE_COMMAND = {"java",
            "-jar",
            "", // This is the JRECreate jar location
            "--dest", "JRE", // This is the folder that you need to put in /usr/local/frc
            "--profile", "compact2",
            "--vm", "client",
            "--keep-debug-info",
            "--debug"
            "--extension", "nashorn"
};

“spearit”…

This should be totally legal for FIRST. The Linux kernel on the roboRIO is simply an interface to the FPGA, the important stuff (sending PWM signals, etc) is done outside of the power of the kernel.

The spirit* of FIRST is to inspire technology, learning how to embed java runtimes on linux kernels is certainly inspiring :slight_smile:

As far as I am aware, it should be legal. One thing you’ll need to be careful of, though, is memory usage. One problem we had when we first started experimenting with java (this was before java 8 was out) was that the jvm used too much memory and crashed on startup. I’m not saying that it will for you, and we haven’t seen this issue since we upgraded to java 8, just be aware of it.