2009年7月29日 星期三

GWT : cannot be resolved to a type

Compile error:
[ERROR] Line 7: The import com.abc.admin.orm.Admin cannot be resolved
[ERROR] Line 86: Admin cannot be resolved to a type

GWT 會依 .gwt.xml 中的 <source> tag 找檔案;
<module>
<source path="client"/>
<source path="orm"/>
....
</module>

但是 source 要和 .gwt.xml 檔在同一個 package 下.
例 : 如果此 .gwt.xml 為 /com/abc/app/gwt/Sample.gwt.xml , GWT 讀取的 Classes 必須在 package com.abc.app.gwt.client 或 com.abc.app.gwt.orm 之下.

如果想引用不同 package 的 classes, 可用 <inherits> tag :

1. /com/abc/app/gwt/Sample.gwt.xml --

<module>
<source path="client"/>
<source path="orm"/>

<inherits name="com.abc.admin.Admin"/>

<entry-point class="com.abc.app.gwt.client.SampleGWTEntry"/>

....
</entry-point>

2. /com/abc/admin/Admin.gwt.xml --

<module>
<source path="client"/>
<source path="orm"/>
</module>

此 module 不需 <entry-point>

** com.abc.app.gwt.client.SampleGWTEntry 就可使用 com.abc.admin.orm 下的 classes了.


Reference:
http://code.google.com/p/google-web-toolkit-incubator/wiki/PathsHandlingFAQ

沒有留言:

張貼留言