- January 16, 2019
var pr = new ConsoleRunner(); pr.exec("python --version");
First of all, we need to start with a fresh Java project. I use a simple maven project for this demo.
Add a dependency for Rhino into pom.xml
<dependencies> <dependency> <groupId>cat.inspiracio</groupId> <artifactId>rhino-js-engine</artifactId> <version>1.7.10</version> </dependency> </dependencies>
Let’s try to evaluate this simple snippet
var a = [2,8,5]; a + a;
First line simply assigns [2, 8, 5] array to the identifier “a”. Eventually we do a simple expression a + a. So the evaluated end-result should be 10
Create RhinoExample.java as per below.
When you execute this it will give 10 as the output as we expected before.
Create ConsoleRunner.java by extending with the ScriptableObject class
Here are some important facts about the above source,
– Overridden getClassName method should always return the current class name.
We need to modify RhinoExample.java by adding our sample code snippet and also by adding a reference to our host object class.
Find Shalitha Suranga on Medium for more tutorials and articles
Happy Coding 👨💻
To apply for internships, please send in your CV to email@example.com with ‘Internship’ in the subject line, and include a brief paragraph as to why you are suited to be an intern at 99X Technology