views:

332

answers:

2

How can I Include Grails generated java class into the grails project?

How can I use the generated class by grails into a java class in the project. Use my Groovy class into a Java class of the Grails project. Accesing his methods, attributes, etc...

Example:

I have a Domain class like this:

package es.prueba.domain
class Author implements Serializable {
  String firstName
  String lastName

  static hasMany = [books: Book]       

  def relatesToMany = [ books : Book ]

  SortedSet books

  static constraints = {
      books(nullable: true)
  }

}

I want to use it in a Java File. In my case I'm using GWT to send objects with the service AuthorService.groovy.

I generated the interfaces with rule: grails generate-gwt-rpc

BookService:

package org.example.client;

import com.google.gwt.user.client.rpc.RemoteService;

public interface BookService extends RemoteService {
    es.prueba.domain.Author getAuthor(int arg0);
}

BookServiceAsync:

package org.example.client;

import com.google.gwt.user.client.rpc.AsyncCallback;

public interface BookServiceAsync {
    void getAuthor(int arg0, AsyncCallback callback);
}

But I get the exception:

No source code is available for type es.prueba.domain.Author; did you forget to inherit a required module?

When I run the app with: grails run-app command.

How can I include source in the project?

Thank you.

A: 

Did you put your domain class in es.prueba.domain package? I don't see a package declaration in your source code example.

cheers

Lee

leebutts
Yes I have, I updated the question.Thanks...
alcoholitro
Do you have a stacktrace with that exception? Is it being thrown by the plugin code or from the core Grails compile step?
leebutts
A: 

I'm not very familiar with the GWT plugin for Grails but it looks more like a standard GWT issue.

From the GWT documentation about how to organize projects:

The default source path is the client subpackage underneath where the Module XML File is stored.

You package name is es.prueba.domain so GWT does not find it when it looks for source. You have to specify it in your module file (let's say Application.gwt.xml) as specified below:

<module>
   <!-- Inherit the core Web Toolkit stuff. -->
   <inherits name="com.google.gwt.user.User"/>

   <!-- add es.prueba.domain as source path -->
   <source path="domain"/>

   <!-- Specify the module entry point class. -->
   <entry-point class="es.prueba.Application"/>
</module>
rochb
`Module: org.example.MyApp.[java] Compiling module org.example.MyApp[java]Computing all possible rebind results for 'org.example.client.MyApp'[java]Rebinding org.example.client.MyApp[java]Checking rule <generate-with class='com.allen_sauer.gwt.log.rebind.LogMessageFormatterGenerator'[java][ERROR] Unable to find type 'org.example.client.MyApp'[java][ERROR] Hint: Previous compiler errors may have made this type unavailable[java][ERROR] Hint:Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly`
alcoholitro
I get this error including the package to load a module in the GWT application.Thanks but I haven't found anyhting to use the generated classes in a GWT module entry point.
alcoholitro
I don't understand your last comment.
rochb
If I add this path: `<source path="domain"/>` the application couldn't find the GWT module.Regards.
alcoholitro
I suspect that org.example.client.MyApp is the path of your module (MyApp.gwt.xml). If you add <source path="domain"/>, GWT is going to look in org.example.client.domain. Because this path does not exist, you get the error. You've got to move your domain package from es.prueba.domain to org.example.client.domain.
rochb