2009-12-17 72 views
0

我正在使用Eclipse版本:3.5.1,GWT 2.0.0,GAE 1.3.0,並且我正在嘗試使用XStream 1.3.2來'序列化'我的Java對象往返xml在GWT的客戶端和服務器端之間。GWT第三方庫問題:包含的代碼

在服務器端,XStream的工作沒有問題。

在客戶端,編譯器會抱怨找不到使用的XStream類的源代碼。我知道這是某種「引用」問題,GWT客戶端類無法自動查找服務器類,但我理解爲什麼這是我正在慢慢發瘋,因爲我嘗試使用各種文章和教程中介紹的方法,這些方法包括如何在GWT中使用第三方庫。

沒有一個工作!

我gwt.xml文件如下:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.1/distro-source/core/src/gwt-module.dtd"> 
<module rename-to='bandmates'> 
    <!-- Inherit the core Web Toolkit stuff.      --> 
    <inherits name='com.google.gwt.user.User' /> 

    <!-- Inherit the default GWT style sheet. You can change  --> 
    <!-- the theme of your GWT application by uncommenting   --> 
    <!-- any one of the following lines.       --> 
    <inherits name='com.google.gwt.user.theme.standard.Standard' /> 
    <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> --> 
    <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>  --> 

    <!-- Other module inherits          --> 

    <!-- Specify the app entry point class.       --> 
    <entry-point class='org.redboffin.bandmates.client.BandMates' /> 
</module> 

我的Eclipse的XStream庫如下:

XStream 
    |__ Access rules : No rules defined 
    |__ Native library location: (None) 
    |__ xstream-1.3.2.jar [path to jar] 
     |__ Source Attachment: xstream-1.3.2-sources.jar [path to source jar] 
     |__ Javadoc location: [path to javadoc] 
     |__ Native library location: (None) 
     |__ Access rules : No restrictions 

我更熟悉Netbeans的,所以我可能會錯誤地設置此功能,但我想我已經將XStream作爲第三方庫包含到了我的Eclipse GWT項目中,並且已經正確引用了二進制jar,源代碼jar和javadoc jar。

客戶

public void onSuccess(String profilesXml) { 

    // Deserialize the xml 
    XStream xstream = new XStream(new DomDriver()); 
    ProfilesImpl profiles = (ProfilesImpl) xstream.fromXML(profilesXml); 

    // Show the RPC result to the user 
    this.friendsWidget.setFriendProfiles(profiles);   
    this.friendsWidget.update(); 

} 

而且GWT編譯器錯誤:拋出錯誤T側方法

Compiling module org.redboffin.bandmates.BandMates 
    Validating newly compiled units 
     [ERROR] Errors in 'file:/C:/Documents%20and%20Settings/Darren/workspace/BandMates/src/org/redboffin/bandmates/client/widgets/FriendsWidget.java' 
     [ERROR] Line 63: No source code is available for type com.thoughtworks.xstream.XStream; did you forget to inherit a required module? 
     [ERROR] Line 63: No source code is available for type com.thoughtworks.xstream.io.xml.DomDriver; did you forget to inherit a required module? 
    Finding entry point classes 
     [ERROR] Unable to find type 'org.redboffin.bandmates.client.BandMates' 
      [ERROR] Hint: Previous compiler errors may have made this type unavailable 
     [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 

我不知道,你可能需要的其他信息來幫助我,但如果你需要的東西,我的天堂」那麼請提問。

感謝遠閱讀本:-)

回答

2

不要你需要導入XStreams包在你的gwt.xml文件。例如。例如:

<inherits name='com.thoughtworks.xstream'/> 

+0

我會盡力的,謝謝喬恩 – Darren 2009-12-17 14:28:04

+0

有了繼承包括標籤,編譯器說: 加載繼承模塊「com.thoughtworks.xstream」 [錯誤]找不到「COM/ThoughtWorks的/ xstream.gwt.xml '在你的類路徑上;可能是拼寫錯誤,或者您可能忘記爲源代碼包含類路徑條目? – Darren 2009-12-17 14:30:06

+1

好吧,我不是GWT專家,但我認爲該jar需要有源代碼(由GWT編譯器需要)和xml文件。有關更多信息,請參閱此博客(http://roberthanson.blogspot.com/2006/05/how-to-package-gwt-components.html)。 – 2009-12-17 14:59:31

1

GWT將Java源代碼編譯爲JavaScript。你不能指向一個普通的罐子。如果您確實必須使用XStream,則需要在客戶端軟件包下包含源代碼或創建單獨的模塊並導入它。

但對我來說,這只是重新發明輪子。你將會有很多工作,並且會比RPC慢。即使有其他客戶使用XML輸出,也許你應該考慮兩種方式。