I thought I should post an update on how on Grails 2.2, since I looked around a lot and found a lot of non-local things that didn't seem to work, eventually made it work as follows:
Project name: gp22 Grails Domain Example name: DemoGrailsDomain JavaClass:src/java/vv/Baggie.java Controller: DemoGrailsDomainController
1: src / java / vv / Baggie.java
package vv; import gp22.DemoGrailsDomain; public class Baggie { public int myresult(int value1) { int resultset=10+value1; return resultset; } public int getResult(int value1) { int aa=myresult(value1); return aa;
DemoGrailsDomainController:
def list(Integer max) { //def myJavaFunction Baggie a=new Baggie() int passit=5 def bb=a.getResult(passit); println "--"+bb
Now make a change of control o on your controller and it will import vv.Baggie
Now, when I get to the list in the browser, println shows:
| The server is running. View on localhost: 8080 / gp22 --15 on my console
You have a value passed from the Grails controller to the processed and returned Java class, the Java class can also call Groovy Domains and retrieve information
Vahid source share