开发者

Include Grails generated Java class into the grails project

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.


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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜