Is there a way to call a method in a Grails service, from a Scala class that is running on the same JVM?
I have seen something similar done from Groovy/Griffon but cannot figure out how to accomplish that in Grails. (http://www.jroller.com/aalmiray/entry/griffon_groovy_scala_working_together)
Basically, one of my Grails controllers calls some Scala code, which should return some values asynchronously. So, I guess, the only way to return those values is by calling back a method in a Grails service.
I found a way of doing it, inspired by the link in the question above, and one of the FAQs in the Grails website.
On the Scala side:
Declare an object similar to the following:
On the Grails side:
Create a class in src/groovy similar to the following:
In your BootStrap.groovy init add the following:
When you call invokeCallback(“example”) in Scala, it will call yourService.yourMethod(“example”)
Note: the jar file with your Scala class should be in the lib folder of you Grails application