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

Avatar

Avatar
Validate 1
Level 1
pilmenkov
Level 1

Likes

0 likes

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
pilmenkov
Level 1

Likes

0 likes

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Validate 1
View profile
pilmenkov
Level 1

23-04-2021

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?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,141 likes

Total Posts

3,167 posts

Correct reply

1,084 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,141 likes

Total Posts

3,167 posts

Correct reply

1,084 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

23-04-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.

 

 

 

Answers (0)