Is it possible to call Groovy script form java in OSGI bundle? | Community
Skip to main content
Level 2
April 23, 2021
Solved

Is it possible to call Groovy script form java in OSGI bundle?

  • April 23, 2021
  • 1 reply
  • 1387 views

I have Groovy Console installed and working in AEM 6.5

 

I have OSGI bundle deployed and active which tries to execute the Groovy script like

ScriptEngine engine = new ScriptEngineManager().getEngineByName("groovy");

And the engine object is null.

 

The call new ScriptEngineManager().getEngineFactories() gives only Oracle Nashorn: ECMAScript engine.

But the /system/console/slingscripting page shows that the groovy is here:

Groovy Scripting Engine 2.0
-------------------------------------
- Language : Groovy, 2.4.15
- Extensions : groovy
- MIME Types : application/x-groovy
- Names : groovy, Groovy

 

What may be missed in my OSGI bundle or in AEM configuration?

Why it does not have access to Groovy when Groovy Console is ok?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by joerghoh

There is a service in Sling, which implements the javax.script.ScriptEngineManager interface, from where you can start.

 

On the other hand, the scripting engines are registered as instances of the ScriptEngineFactory, so you can reference them directly.

 

 

 

1 reply

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
April 23, 2021

There is a service in Sling, which implements the javax.script.ScriptEngineManager interface, from where you can start.

 

On the other hand, the scripting engines are registered as instances of the ScriptEngineFactory, so you can reference them directly.

 

 

 

pilmenkovAuthor
Level 2
April 23, 2021

Thank you Jörg_Hoh, the option 1 is perfect!

It was enough just to add to my @8220494 the following filed:

@3214626
ScriptEngineManager scriptEngineManager;