Add Nashorn Hello World project

- Gradle 9.5.1 (Groovy DSL) build with java + application plugins
- Nashorn standalone engine (org.openjdk.nashorn:nashorn-core:15.6)
- HelloNashorn.java: runs JS via NashornScriptEngineFactory
This commit is contained in:
OpenCode
2026-05-28 04:45:16 +00:00
commit 01f680d6e3
8 changed files with 380 additions and 0 deletions
@@ -0,0 +1,20 @@
package com.example;
import org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory;
import javax.script.ScriptEngine;
public class HelloNashorn {
public static void main(String[] args) throws Exception {
NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
ScriptEngine engine = factory.getScriptEngine();
engine.eval("print('Hello World from JavaScript!')");
String result = (String) engine.eval(
"var greeting = 'Hello from Nashorn on JDK ' + java.lang.System.getProperty('java.version');" +
"greeting"
);
System.out.println(result);
}
}