What is Nasven? Quoting Lukas Eder:
"Nasven = Nashorn + Maven. A tool to get Maven artifacts in scope for Nashorn script execution."
You must have installed in your environment the following softwares:
- Java SE 8
- Apache Maven 3+
You can install on your Linux-based environment with the following command:
$ curl -sSL j.mp/installnasven | sh
You can use the Docker image nasven/nasven.js published in Docker Hub.
# sudo docker run -it nasven/nasven.js /nasven/samples/helloworld
You can also map and run a local (on host) application:
# sudo docker run -it -v `pwd`/samples/hellodocker:/app nasven/nasven.js
The samples repository contains several Nasven applications. One of those samples is the jaxrs sample that uses the JAX-RS Client API. This sample application is coded inside the file index.js of the JAX-RS sample. Prior to Nasven.js, in order to run this application sample, a developer would have to download all the dependencies of JAX-RS Client API, and an implementation of the specification. But it is much easier to use Apache Maven to depend on those artifacts. The configuration of this sample application is defined in the file package.json. To run this application, use one of the following commands:
$ jjs -scripting nasven.js -- samples/jaxrs $ ./nasven samples/jaxrs
You can read arguments inside your code with ''arguments'', ''arguments'', and so on.
Application Definition File package.json
Check the samples repositoryr for more examples of the package.json files with defined Maven dependencies.
Every application executed with Nasven.js will have Nasven itself loaded to provide access to features defined in nasven.js:
- require('path/to/file.js'): same as Nashorn load(), but only for local files and this will be watched for updates and reloaded on the fly.
- daemon(): it will create a deamon Thread to keep the application up and running.
- exec('command', suppress): same as Nashorn exec() except it will print output on demand if suppress is false. By default output is suppressed. Optional argument.
- console.log('text'): same as print().