tags:

views:

468

answers:

11
+1  A: 

SpiderMonkey and Rhino seem to be pretty much related. SpiderMonkey seems to be a C-library for executing JS, while Rhino is a Java-ditto.

Henrik Paul
+10  A: 

JavaScript does not have to be run in a browser if you use an ECMAScript engine. Actually, both SpiderMonkey and Rhino are ECMAScript engines.

Flash's ActionScript is another ECMAScript derived language that doesn't have to run in a browser.

DavGarcia
there's also dmd script http://www.digitalmars.com/dscript/
hasen j
... and its ECMAScript* instead
Pablo Cabrera
Oops, I'll fix that. Thanks Pablo!
DavGarcia
+1  A: 

Yes, JavaScript Virtual Machines exists outside of the browser. Here's a list of specially tailored server side adaptations.

I personally use it Spidermonkey on the command line to try code out. Rhino is the same adaptation of ECMAScript as Spidermonkey (same language implementation) but Rhino runs on the Java VM, and Spidermonkey was written in C.

Zach
+2  A: 

I've heard good things about Jaxer.

By the far the most popular/attractive part of these server-side javascript solutions is in regards to data validation. You can use the same code that you use to validate forms client-side again on the server to ensure their integrity. This comes really useful in simply being DRY and not getting rules out of sync when something changes.

Paolo Bergantino
+2  A: 

As well as VBScript, classic ASP pages can use JScript as the underlying script language. You can run JScript programs on the Windows command line by using CSCRIPT.EXE. In fact, it's the same scripting engine, and it's extensible to support any number of languages.

Roger Lipscombe
http://aspjavascript.com/
voyager
+4  A: 

List of JS interpreters that I know of, that can run standalone or embedded with other code:

orip
You could also add Jint (http://jint.codeplex.com) to the list
Sébastien Ros
@sebastienros agreed - your project looks cool!
orip
A: 

As have been noted, Rhino is a JavaScript engine written in Java.

Java 6 has a new scripting engine facility, appropriatedly called the Java Scripting API in the javax.script package, for which a Rhino-based engine is available for use out of the box. I'm not sure if this is available on Java EE, but it is a standard feature of Java SE.

Using the Scripting API is quite simple and allows for Java applications to run scripts written in Javascript quite easily. If you require scripting in your application, there's no need to write your own interpreter -- just use the Scripting API. Also, the script engine has access to the Java class libraries, so it integrates nicely to perform tasks within your application as well.

For example, calculating the square root of 4, using the Scripting API is as simple as:

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
engine.eval("var x = java.lang.Math.sqrt(4);");
engine.eval("println(x);");

In the context of using this on the server side, I can envision an external Jaavscript being executed by Rhino and the results are then embedded onto the dynamically-generated HTML page that is being served. This way, features could be added or modified without making changes to the web application itself. The Javascipt scripts themselves can act more or less like plugins for the main application.

The Java Scripting Programmer's Guide has several examples which are built up step-by-step to introduce the features of the Java Scripting API.

Javascript doesn't necessarily have to be confined to a browser. As with any scripting language, it really depends on where the scripting engine is being hosted.

coobird
A: 

There is also HTTPUnit which is more of a browser simulator, so, it allows you to interact with the DOM.

http://httpunit.sourceforge.net/

Brian Whitlock
A: 

Have you checked out John Resig's post about creating a serverside Javascript engine with Rhino?

(http://ejohn.org/projects/bringing-the-browser-to-the-server/)

leeand00
A: 

choosing an engine

the other answers already mentioned several JS engines. one very important factor in deciding which one to use should be the language in which it is implemented (C, C++ or Java are the choices), since this "host language" will be the one you have access to very easily.

for example if you use rhino, you can easily access the whole java standardlib from javascript code (typically you will write wrappers in JS so you don't have all those java-lib calls sprinkled in your JS code).

choosing a framework

there were several mentioned alread. I like helma most. old and tried. lots of big sites run on it. there is also a sexy but very alpha version of helma over at github: http://github.com/hns/helma-ng/

serverside JS

you might also be interested in this group, they try to unify how JS works serverside (provide a standardlib, etc). the just started this group, but have a lot of smart people working on serversideJS for years:

https://wiki.mozilla.org/ServerJS

oberhamsi