« July 2009
SunMonTueWedThuFriSat
   
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
       
Today
XML

Blog::Navigation

GetJava Download Button
Get the Source
Personal Blog

Blog::Referers

Today's Page Hits: 472

Powered by Roller Weblogger.
« Javac Tree API -... | Main | Updated Groovy and... »
20061211 Monday December 11, 2006

The horse starts running (JDK 6 released)!

Yes, JDK 6 has been released today. As many of you know already, scripting is one of the important features of JDK 6. Scripting API is in the javax.script package which is specified by JSR-223. It is very simple API to use scripting languages from Java code. To use scripting language from your Java code, you need to have JSR-223 compliant "script engine" - i.e., implementation of the javax.script API for your language of choice. Sun's implementation of JDK 6 comes with JavaScript script engine - which is based on Mozilla's Rhino implementation. So, you can "eval" JavaScript code from your Java code!

What is Scripting API?

Scripting API helps you

"Hello World" with Scripting

Simple main class to evaluate JavaScript to print "hello world":


import javax.script.*;

public class Main {
  public static void main(String[] args) throws Exception {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine jsEngine = manager.getEngineByName("JavaScript");
    jsEngine.eval("println('hello world')");
  }
}
There are two samples in JDK installation:

If you are interested in using scripting on the serverside code, you may want to look at the Phobos project. This project uses JSR-223 scripting feature.

References



( Dec 11 2006, 05:39:29 PM IST ) Permalink Comments [1] del.icio.us | furl | simpy | slashdot | technorati | digg

Comments:

The jrunscript utility distriuted with JDK 1.6 and the ScriptEngineMnager force the ScriptEngine for a language to accept SimpleBindings in the setBindings method. This seems to be at variance with the basic design in which Bindings is just an interface and the language is free to implement it any way convenient.

Posted by scriptics on December 14, 2006 at 12:45 PM IST #

Post a Comment:

Comments are closed for this entry.
Copyright (C) 2005, A. Sundararajan's Weblog