Lyndon Armitage Lyndon is a general Developer. He has a keen interest in AI and Games Programming and runs a blog that he periodically updates.

How to make use of Nashorn on Java 7

1 min read

Nashorn is the new Oracle library to replace the reliable and now ageing, Rhino JavaScript engine for Java. It makes use of new JVM features (added specially) which should give it a large speed boost.

But like many developers we wanted to be able to evaluate it and have the added benefits of using Nashorn now without going through the hassle of building the OpenJDK8 to work with (a task that I have attempted previously).

Luckily somebody called ramonza on BitBucket has created a backport of the Nashorn repository compatible with JDK7, that is very easy to build and start playing with.

The BitBucket page can be located here: and to get started using it all you need to do is the following:

  1. First clone the repository to a directory of your choice.
  2. Next attempt to build the repository using the ant command: ant -f make/build.xml
    1. If the build fails due to an issue with dynalink (as mine did) somebody has graciously provided a patch file to fix this issue here. Apply it to the repository and try the build again and it should succeed
  3. Now you should see a few files in the dist folder of the cloned repository. These include the nashorn.jar as well as the javadocs for nashorn.
  4. Finally all you need to do is add the following Virtual Machine options to your Java programs to make Nashorn available to them:

And that’s it! You should now be able to use Nashorn in your Java 7 programs. To test this you can run this simple Java program that will list the available Script Engines:

import javax.script.*;
public class NashornTest {
public static void main(String args[]) {
ScriptEngineManager manager = new ScriptEngineManager();
for (ScriptEngineFactory f : manager.getEngineFactories()) {
ScriptEngine nashorn = manager.getEngineByName("nashorn");
if(nashorn != null) {
System.out.println("Nashorn is present.");
else {
System.out.println("Nashorn is not present.");
public static void printBasicInfo(ScriptEngineFactory factory) {
System.out.println("engine name=" + factory.getEngineName());
System.out.println("engine version=" + factory.getEngineVersion());
System.out.println("language name=" + factory.getLanguageName());
System.out.println("extensions=" + factory.getExtensions());
System.out.println("language version=" + factory.getLanguageVersion());
System.out.println("names=" + factory.getNames());
System.out.println("mime types=" + factory.getMimeTypes());

When run with nashorn added to the boot classpath you will see the message “Nashorn is present.” as well as some basic information on the available scripting engines. Running it without adding nashorn to the boot classpath you will see the message “Nashorn is not present.” along with basic information on only Rhino.

Hopefully this will help you to get started with using and developing applications that make use of Nashorn.

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

Lyndon Armitage Lyndon is a general Developer. He has a keen interest in AI and Games Programming and runs a blog that he periodically updates.

Java 13 Articles-series index

Here at IDRsolutions we always like to research and test the key new features in each Java release, as well as some of the hidden...
28 sec read

Why we wrote our own Java jpeg2000 libraries

JPEG2000 is an important image file format which offers significant benefits over JPEG. For our specific usage it does generate significantly smaller file sizes...
Mark Stephens
52 sec read

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2019. All rights reserved.