Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

CHAPTER 22: Scripting Support in Spring > Scripting Support in Java

Scripting Support in Java

Starting with JSE 6, the Scripting for the Java Platform API (JSR-223) is bundled into the JDK. Its objective is to provide a standard mechanism for running logic written in other scripting languages on the JVM. Out of the box, JDK 6 comes bundled with the engine called Mozilla Rhino, which is able to evaluate JavaScript programs. This section will give you an introduction to the JSR-223 support in JDK 6.

In JDK 6, the scripting support classes reside in the package javax.script. First let's develop a simple program to retrieve the list of script engines. Listing 22-1 shows the class content.

Listing 22-1. Listing Scripting Engines

package com.apress.prospring3.ch22.jsr223;

import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;

public class ListScriptEngines {

   public static void main(String[] args) {

      ScriptEngineManager mgr = new ScriptEngineManager();

      for (ScriptEngineFactory factory : mgr.getEngineFactories()) {
         String engineName= factory.getEngineName();
         String languageName = factory.getLanguageName();
         String version = factory.getLanguageVersion();
         System.out.println("Engine name: " + engineName + " Language: " + languageName + " images
version: " + version);
      }
   }
}

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial