Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java + Scripting languages (JSR 223)

I'm designing a Framework which I want to attach to the scripting language API to make it more versatile and easier to use (for some things I really prefer the scripting way myself ;). With languages like JRuby, Jython or Rhino (JavaScript) there are interpreters for many popular scripting languages available and as far as I read, all of them implement the Java Scripting language API to embed them in your Java application.

Do you have experience with running it that way? I'm especially interested in handling e.g. associative arrays (or Java Beans). How is the performance (e.g. compared to a CGI like approach or the native Java way)? Would it be easy to switch between the different interpreters (of course it is an API specification but I still don't know on how to handle language specific issues)?

like image 787
Daff Avatar asked Jul 20 '09 18:07

Daff


People also ask

What JSR 223?

JSR223 (spec ) is a standard scripting API for Java Virtual Machine (JVM) languages . The JVM languages provide varying levels of support for the JSR223 API and interoperability with the Java runtime.

What scripting language does Java use?

BeanShell is a commonly used scripting solution for Java. It's a scripting language which is very Java-like. Other solutions exist which use the Java infrastructure and JVM, but with a different language. e.g. Scala, Groovy and Jython (a Java-compatible Python).

What is default Scripting language used in JVM Platform?

There is no requirement for a given Java virtual machine (JVM) to include any engines by default, but the Oracle JVM (Java 6 and later) includes a JavaScript engine, based on Rhino version 1.6R2 before Java 8, and Nashorn since Java 8.

What is Java scripting API?

The Java Scripting API consists of classes and interfaces from the javax.script package. It is a relatively small and simple package with the ScriptEngineManager class as the starting point.


1 Answers

I have run Rhino, Jython, JRuby, and Groovy. There is the obvious language difference between them all and performance is pretty slow across the board. I've found that Groovy was the easiest to create a domain specific language (DSL) for my application. Groovy was also the easiest language to control in terms of package accessibility and runtime variables but required using Groovy API to do it instead of JSR-223.

I feel like the Groovy tooling/documenation/api meshes better with the JVM, but certainly ruby/python have quite a following and the syntax may be more comfortable for some. Ultimately I'd try them all out in your framework and choose one. Multiple scripting languages sounds nice but might be a headache to debug/support/transition.

after though: You could check into BeanShell

like image 199
basszero Avatar answered Oct 03 '22 19:10

basszero