Skip to content

mszu/nashorn-scripting-api-fragment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Nashorn Scripting API Fragment

If you're running AEM 6.1 (or 6.0 with SP2) with Java 8, you might want to use the new Nashorn JavaScript engine to do cool server-side JS stuff. Unfortunately, you can't -- even though nashorn.jar is on the system classpath, it is not available to the bundles inside the OSGi container.

This project fixes that.

Requirements

  • AEM 6.1 (or 6.0 with service pack 2, see Adobe docs for installation instructions)
  • Java 8 (the version used to build this project doesn't matter, but AEM needs to be running with JRE/JDK 8)

Build + Deploy

Use Maven to build this project.

To build and deploy to a running instance, run mvn clean install -P autoInstall from the project root. By default the host and port are assumed to be localhost:4502 with user:password as admin:admin. These can be changed by appending -Dcrx.(host|port|user|password)=<correct-value> as appropriate (e.g. -Dcrx.port=4503).

How does it work?

The build artifact from this project is an OSGi bundle fragment which attaches to the system bundle and modifies its Export-Package directive to include the Nashorn scripting package.

Now What?

Installing this fragment only exposes the Nashorn scripting package to the other bundles in your OSGi environment (note that this is NOT the same as registering a Sling scripting engine, so you probably can't use getEngineByName('nashorn') until you do). It is up to you to write code that uses it, e.g.

ScriptEngine engine = new jdk.nashorn.api.scripting.NashornScriptEngineFactory().getScriptEngine();
engine.eval('var a = "world"; print("Hello " + a);');

About

An OSGi bundle fragment that exposes the Nashorn scripting API package

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published