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.
- 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)
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
).
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.
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);');