2012-03-24 62 views
1

GWT in Action,2ed(MEAP),218頁表示我們可以在客戶端代碼中引用註釋中的服務器端類,如@ProxyFor。這是符合邏輯的,什麼我希望......從GWT編譯但我得到異常:GWT RequestFactory:在客戶端程序包中使用服務器類

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 

我不引用任何服務器端類,除了在註釋:

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); 
    } 

} 

回答

3

一段時間後,我遇到了同樣的問題。你的代碼沒有問題。默認情況下,GWT編譯器不會包含註釋引用的用於編譯的類,這很瘋狂。所以,你看到AnnotatedRfqService cannot be resolved to a type的原因是因爲這些類實際上並沒有被編譯。解決方案是在嘗試編譯GWT模塊之前(通過Ant,大概)運行Java Compiler編譯所有內容。

我問(回答)同樣的問題在這裏:https://stackoverflow.com/a/8766677/291180

出於某種原因,GWT忽略該類型import聲明,但他們並不認爲這是一個錯誤。荒謬。 http://code.google.com/p/google-web-toolkit/issues/detail?id=5378