Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages of using Rhino (mozilla's rhino)

I've been reading about Rhino as a useful way to implement JavaScript inside my Java code.

After reading for a while, searching in google and here, I couldn't find a real reason for which I would use JavaScript inside Java.

Could you point some real world advantages you find on using Rhino for a regular Java application?

like image 256
Santi Avatar asked Sep 24 '09 14:09

Santi


2 Answers

Note that since Java 6, the scripting API is in the standard Java library - see the documentation of the package javax.script. The API in javax.script is an adapted version of Rhino. The scripting API supports not only JavaScript, but many other scripting languages.

See Java Scripting Programmer's Guide

The front page there mentions some reasons you might want to use scripting:

  • Application extension/customization: You can "externalize" parts of your application - like configuration scripts, business logic/rules and math expressions for financial applications.
  • "Command line" shells for applications -for debugging, runtime/deploy time configuration etc. Most applications have a web-based GUI configuaration tool these days. But sysadmins/deployers frequently prefer command line tools. Instead of inventing ad-hoc scripting language for that purpose, a "standard" scripting language can be used.

An example: You can script Oracle Weblogic using Python scripts, for example to configure your application server domain, to start or stop the server and to do other administration tasks.

like image 147
Jesper Avatar answered Sep 18 '22 23:09

Jesper


  1. Processing XML with Rhino and E4X is a joy compared to most of the Java XML APIs
  2. You have existing JavaScript that "just works" and you don't want to re-write it. This can happen if you have some calculation or processing happening on the client side and move it to the server.
  3. All kinds of neat caching and code loading tricks.
  4. Your problem is better solved by a more dynamic language then Java.
  5. List comprehensions ;)
like image 44
JonMR Avatar answered Sep 20 '22 23:09

JonMR