New to scripting with Java and Nashorn, any tutorials?

Michael Yousef picture Michael Yousef · Mar 25, 2014 · Viewed 10.7k times · Source

Are there any good tutorials or the likes for getting stated with this? I have yet to do any scripting in Java, though I am familiar with JavaScript already. Thanks. Essentially, I want to use JavaScript/XML to handle part of my project. I know Java 8 introduced JavaScript support via Nashorn. I want to learn how this works. I know it involves using javax.script, but I don't know how that package works nor do I understand how Nashorn works.

Answer

Benjamin Winterberg picture Benjamin Winterberg · Apr 6, 2014

I played a lot with nashorn in the last couple of weeks. I wrote all my findings in an example-driven tutorial:

http://winterbe.com/posts/2014/04/05/java8-nashorn-tutorial/

It covers the following topics:

  • calling javascript functions from java code
  • calling java methods from javascript
  • using java classes from within javascript
  • summary of all language extensions (e.g. for each)

I hope it's helpful for you to start with Nashorn.