Skip to content

Instantly share code, notes, and snippets.

@jmesnil
Created July 25, 2008 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmesnil/2425 to your computer and use it in GitHub Desktop.
Save jmesnil/2425 to your computer and use it in GitHub Desktop.
How to execute JavaScript code from a Java class
public class JavaScriptTest {
public static void main(String[] args) throws Exception {
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
engine.eval("print('hello, world!')");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment