adam bien's blog

Setting The Classpath For Nashorn Script in jjs / Java 8 📎

The Java 8 jjs interpreter accepts the -cp / -classpath argument. After setting the classpath, all the classes become available from within the executable script.

A utility class com.airhacks.naslib.Inspector in the naslib.jar (this is an sample jar) becomes available for Nashorn after setting the jjs classpath:


#!/usr/bin/jjs -cp ./naslib/target/naslib.jar -fv
//built-in variable
var args = $ARG;

var Inspector = com.airhacks.naslib.Inspector;
//class from jar, calling a static method
Inspector.inspect(args);

In case this post looks a bit crazy to you, you would enjoy the Java 8 / Java EE 7 "More Power with Less Code" workshop :-).