Advantages of using Rhino (mozilla's rhino)
Asked Answered
B

5

14

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?

Baziotes answered 24/9, 2009 at 14:37 Comment(1)
In addition to what others said, game development is a great example. Having external scripts is a very common practice in game development for a number of reasons, and if you're writing a game in Java and want to use JavaScript as your scripting language, Rhino is great.Metabolism
V
11
  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 ;)
Vain answered 4/10, 2009 at 3:33 Comment(1)
You're right. I'd use Jython instead of JavaScript for covering most of the points you've given. But your probably a java guy wouldn't.Baziotes
U
15

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.

Unionize answered 24/9, 2009 at 14:51 Comment(2)
What are these other languages?Faeroese
@WesleiPrudencio see #11838869Unionize
V
11
  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 ;)
Vain answered 4/10, 2009 at 3:33 Comment(1)
You're right. I'd use Jython instead of JavaScript for covering most of the points you've given. But your probably a java guy wouldn't.Baziotes
P
6

The benefit of embedding a script language like javascript into your software is that you can offer others a way to write plugins for your software without giving the source code away.

A reason to write the whole app in another language is that you are able to write an app for a company which deploys it in their Java EE environment without having to learn Java.

Prestonprestress answered 24/9, 2009 at 14:50 Comment(2)
To enable others to plug into your app without giving away the source code, all you need is a package with some interfaces.Stone
IBM Maximo 7.5 + does this (Rhino or Jython), and the added benefit is that you avoid customizing their software, which makes upgrades smoother.Ayah
R
4

We use JS (via Rhino) for a DSL in one of our products. It isn't a great DSL, but that is a fault of how we use JS, rather than Rhino.

Rosalindarosalinde answered 13/9, 2012 at 5:38 Comment(2)
I'm all for short and sweet, but it's not clear to me what DSL refers to in this context. Would you care to enlighten me?Copyist
DSL = Domain specific language. Basically, we needed a language that allowed people to express rules. Javascript is good because it is easy to setup what the user can and cannot do by specifying what is in the global context. No includes required.Rosalindarosalinde
I
0

If you considering to .Net also, I suggests to get along with Rhino.

Besides Java enviroments, rhino is one of the best performance interpreter on .NET environment (using IKVM). On the other hands, nashorn is very slow on .net.

Porting your own Rhino project to .NET is not so difficult.

Intercommunicate answered 29/11, 2015 at 10:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.