By Bruno.Borges-Oracle on Apr 13, 2015
For example, let's say you want to test the Streams API in JDK 8. In traditional Java development, even without an IDE, you'd have to open a text editor, create a Java class, then compile it with javac, and finally run it with java command. But you just want to try an API, right? So you'd rather prefer to skip that code/compile/run and just do... code/run!
Introducing you project Nasven.js
nasven.js is a tiny Nashorn script that will invoke Maven on top of a POM generated based on a configuration file. It will then call the Dependency Plugin to download all the dependency tree of your application, setup the classpath, and then invoke jjs of your actual application with the full classpath properly configured for you, automatically!
Here's how it works:
1) First you setup a configuration file, for example appdef.js:
|1 2 3 4 5 6||
2) Then you code your application, that in this case depends on the JAX-RS Client API implemented by GlassFish's Jersey. For example jaxrs.js:
|1 2 3 4 5||
3) Finally you just need to invoke nasven.js. But make sure you have Maven properly installed and configured (in your PATH) as well JDK 8 of course.
$ jjs -scripting nasven.js -- appdef.js
$ ./nasven.js -- appdef.js
You can also use the Docker image nasven/nasven.js to run right out of the box. The image contains OpenJDK 8 and comes with Nasven.js and their samples, as well Maven installed and with most common dependencies already downloaded for you. Here's how you run on your laptop the JAX-RS Sample (confirm you have Docker already installed);
# docker run -it nasven/nasven.js /nasven/samples/jaxrs
And that's it! Let me know if you liked this! :-)
Learn more about Nashorn