Mozilla Rhino (
http://www.mozilla.org/rhino/
) allows JavaScript to be embedded in Java processes. This is included with JDK 6 but can be used directly without the new JDK 6 scripting extensions in earlier JDKs. Under Rhino, JavaScript can access Java classes directly by importing them. This uses the following syntax:
importPackage(Packages.java.text);
/* use something from java.text */
var sqlDateFormat = new SimpleDateFormat("yyyyMMdd");
var cobDate = sqlDateFormat.format(command.getCobDate());
It would be spiffy if these imports were handled correctly for code analysis, completion, and Go To Declaration. Currently we have to turn off all inspections when working on all of our embedded JavaScript.