Using Nashorn Script Engine in AEM

Avatar

Avatar
Validate 1
Level 1
Nitin_Tyagi
Level 1

Like

1 like

Total Posts

9 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
Nitin_Tyagi
Level 1

Like

1 like

Total Posts

9 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
Nitin_Tyagi
Level 1

15-10-2015

Hi All,

I am currently working on  AEM SP2 with JDK8 & trying to build a Handlebar Script Engine in AEM. For the Handlebar Compilation & processing we were loading the Nashorn Script Engine inside AEM & the Nashorn will be used to evaluate handlebars.js & other processing. I am loading the Nashorn engine as per instructions on http://www.oracle.com/technetwork/articles/java/jf14-nashorn-2126515.html with below lines of code. But the nashorn Engine is not initializing.

ScriptEngineManager engineManager = new ScriptEngineManager(); ScriptEngine engine = engineManager.getEngineByName("nashorn");

Another option which I tries was to Initialize  ScriptEngineManager via OSGi @Reference Notation. When I do that It gives me all the Registered Script Engines in AEM available @ http://localhost:4502/system/console/status-slingscripting , but again Nashorn isn't among them.

Can anyone help me how to load Nashorn Engine inside AEM or do I have to do a Custom Implementation OF Nashorn Script Engine in AEM?

Thanks

Nitin

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 10
Employee
justin_at_adobe
Employee

Likes

76 likes

Total Posts

528 posts

Correct reply

259 solutions
Top badges earned
Give Back 10
Give Back 5
Give Back 3
Give Back
Ignite 5
View profile

Avatar
Give Back 10
Employee
justin_at_adobe
Employee

Likes

76 likes

Total Posts

528 posts

Correct reply

259 solutions
Top badges earned
Give Back 10
Give Back 5
Give Back 3
Give Back
Ignite 5
View profile
justin_at_adobe
Employee

15-10-2015

From within AEM, the available ScriptEngineManager does not pick up ScriptEngines (like Nashorn) which are registered outside the OSGi framework. You will need to register Nashorn with Sling's ScriptEngineManager. Better yet would be if Nashorn was available as an OSGi bundle, in which case it could just be dropped in. This is the case, for example, with Groovy.

Answers (3)

Answers (3)

Avatar

Avatar
Validate 1
Level 1
Nitin_Tyagi
Level 1

Like

1 like

Total Posts

9 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
Nitin_Tyagi
Level 1

Like

1 like

Total Posts

9 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
Nitin_Tyagi
Level 1

15-10-2015

Thanks for your response Peter. Yes It's not yet added in the AEM's list of Script Engines. That's the reason I am trying to load it directly from JDK considering nashorn.jar is already in the classpath.

ScriptEngineManager engineManager = new ScriptEngineManager();

ScriptEngine engine = engineManager.getEngineByName("nashorn");

It looks like I will have to create a new NashornScriptEngine in AEM using nashorn.jar.

Thanks

Nitin

Avatar

Avatar
Validate 25
MVP
PuzanovsP
MVP

Likes

140 likes

Total Posts

543 posts

Correct reply

165 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Contributor 2
Ignite 10
View profile

Avatar
Validate 25
MVP
PuzanovsP
MVP

Likes

140 likes

Total Posts

543 posts

Correct reply

165 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Contributor 2
Ignite 10
View profile
PuzanovsP
MVP

15-10-2015

Hey Nitin,

Current AEM6 runtime is Rhino and it's implementation can be found here:

org.apache.sling.scripting.javascript.RhinoJavaScriptEngine

As per my current understanding Nashorn is not supported in AEM 6, even so it's added as default engine in JDK 8.

Peter

Avatar

Avatar
Level 1
anisazula
Level 1

Likes

0 likes

Total Posts

1 post

Correct reply

0 solutions
View profile

Avatar
Level 1
anisazula
Level 1

Likes

0 likes

Total Posts

1 post

Correct reply

0 solutions
View profile
anisazula
Level 1

10-09-2020

this is nice psot thanks for sharing this ----We will provide any antivirus installation error solution you can use this support service team members and find a solution to complex issues related to antivirus.

https://garminexpress.global/
http://rand-mcnally-gps-update.com/
http://belkin-setup.com/
http://mywifi-extt.com/