Search code examples
gwtrequestfactory

GWT RequestFactory: using server classes in client package


GWT in Action, 2ed (MEAP), p.218 says that we can reference server-side classes in annotations like @ProxyFor in the client code. That's logical and what I would expect... however I'm getting exceptions from the gwt compiler:

Validating newly compiled units
[ant:java]       Errors in 'file:/C:/git/mvp_ap_test/src/de/mycompany/client/AppRequestFactory.java'
[ant:java]          Line 9: The import de.mycompany.server.AnnotatedRfqServiceLocator cannot be resolved
[ant:java]          Line 10: The import de.mycompany.server.dao.AnnotatedRfqService cannot be resolved
[ant:java]          Line 15: AnnotatedRfqService cannot be resolved to a type
[ant:java]          Line 15: AnnotatedRfqServiceLocator cannot be resolved to a type
[ant:java]          Line 15: Class<AnnotatedRfqServiceLocator> cannot be resolved to a type
[ant:java]       Errors in 'file:/C:/git/mvp_ap_test/src/de/mycompany/client/proxy/AnnotatedRfqProxy.java'
[ant:java]          Line 9: The import de.mycompany.server.AnnotatedRfqServiceLocator cannot be resolved
[ant:java]          Line 10: The import de.mycompany.server.domain.AnnotatedRfq cannot be resolved
[ant:java]          Line 12: AnnotatedRfq cannot be resolved to a type
[ant:java]          Line 12: AnnotatedRfqServiceLocator cannot be resolved to a type
[ant:java]          Line 12: Class<AnnotatedRfqServiceLocator> cannot be resolved to a type
[ant:java]       Errors in 'file:/C:/git/mvp_ap_test/src/de/mycompany/client/proxy/AnnotationProxy.java'
[ant:java]          Line 6: The import de.mycompany.server.domain.Annotation cannot be resolved
[ant:java]          Line 8: Annotation cannot be resolved to a type
[ant:java]    Removing invalidated units

I don't reference any server-side classes except in the annotations:

package de.mycompany.client;

import com.google.web.bindery.requestfactory.shared.Request;
import com.google.web.bindery.requestfactory.shared.RequestContext;
import com.google.web.bindery.requestfactory.shared.RequestFactory;
import com.google.web.bindery.requestfactory.shared.Service;

import de.mycompany.client.proxy.AnnotatedRfqProxy;
import de.mycompany.server.AnnotatedRfqServiceLocator;
import de.mycompany.server.dao.AnnotatedRfqService;

public interface AppRequestFactory extends RequestFactory {
    AnnotatedRfqRequest annotatedRfqRequest();

    @Service(value = AnnotatedRfqService.class, locator = AnnotatedRfqServiceLocator.class)
    public interface AnnotatedRfqRequest extends RequestContext {
       Request<AnnotatedRfqProxy> findOne(String id);
    }

}

Solution

  • I ran into the same problem awhile back. There is nothing wrong with your code. By default, the GWT Compiler will not include classes referenced by annotations for compilation, which is crazy. So, the reason that you are seeing AnnotatedRfqService cannot be resolved to a type is because those classes aren't actually being compiled at all. The solution is to run the Java Compiler (through Ant, presumably) to compile everything before you try to compile the GWT module.

    I asked (and answered) the same question here: https://stackoverflow.com/a/8766677/291180

    For some reason, GWT ignores the import statement for the type, yet they don't consider this a bug. Ridiculous. http://code.google.com/p/google-web-toolkit/issues/detail?id=5378