Skip to content

Instantly share code, notes, and snippets.

@hrkt
Last active August 29, 2015 14:14
Show Gist options
  • Save hrkt/042c9764fe7e3d521133 to your computer and use it in GitHub Desktop.
Save hrkt/042c9764fe7e3d521133 to your computer and use it in GitHub Desktop.
download rhino&engine and run sample
#!/bin/sh
# 2015/2/1
#
# A script for downloading rhino & engine source, build jars, and write & execute simple program.
#
# see https://java.net/projects/Scripting
# https://wiki.openjdk.java.net/display/Nashorn/Using+Rhino+JSR-223+engine+with+JDK8
# change this variable
RHINO_VERSION=rhino1.8.0-SNAPSHOT
echo -- downloading Rhino
git clone https://github.com/mozilla/rhino.git
cd rhino
ant jar
JS_JAR=rhino/build/${RHINO_VERSION}/js.jar
cd ..
echo -- downloading JavaScript engine
svn co https://svn.java.net/svn/scripting~svn/trunk/engines/javascript
cp -f ${JS_JAR} javascript/lib
cd javascript/make
ant all
cd ../..
JS_ENGINE_JAR=javascript/build/js-engine.jar
TARGET_DIR=result
mkdir ${TARGET_DIR}
cp ${JS_JAR} ${TARGET_DIR}
cp ${JS_ENGINE_JAR} ${TARGET_DIR}
echo done.
echo -- write source
echo "import javax.script.*;\n\
public class Main {\n\
public static void main(String[] args) throws Exception {\n\
ScriptEngineManager m = new ScriptEngineManager();\n\
// specifically look for "rhino" engine\n\
ScriptEngine engine = m.getEngineByName(\"rhino\");\n\
System.out.println(\"engine:\" + engine.getClass().getSimpleName());\n\
System.out.println(engine.eval(\"33 + 232\"));\n\
}\\n
}"> ${TARGET_DIR}/Main.java
cd ${TARGET_DIR}
echo -- compile
javac -cp .:js.jar:js-engine.jar Main.java
echo -- execute
java -cp .:js.jar:js-engine.jar Main
cd ..
echo "rm -rf javascript rhino result" > cleanup.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment