tags:

views:

274

answers:

2

Hello :-)

I am using Eclipse Version: 3.5.1, GWT 2.0.0, GAE 1.3.0 and I am trying to use XStream 1.3.2 to 'serialize' my Java objects to and from xml between the client and server sides of GWT.

On the server side, XStream works without issue.

On the client side, the compiler complains that it cannot find source code for the XStream classes used. I understand that this is some sort of 'referencing' issue where GWT client classes cannot automatically find server classes and I understand why this is however, I am going slowly insane as I try to use the approaches described in various articles and tutorials that cover how to use 3rd party libraries in GWT.

None of them work!

My gwt.xml file is as follows:

<?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"&gt;  
<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>

My Eclipse XStream Library is as follows:

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

I am more familiar with Netbeans and so I may be setting this up incorrectly, but I think I have included XStream into my Eclipse GWT project as a third party library and have correctly referenced the binary jar, the source jar and the javadoc jar

The client side method that throws the error:

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

}

And the GWT Compiler error:

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

I'm not sure what other information you may need to help me but if you need something I haven't provided then please ask.

Thanks for reading this far :-)

+1  A: 

Don't you need to import your XStreams package in your gwt.xml file. E.g. something like:

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

?

jon hanson
I will try that, thanks Jon
Darren
With that inherits tag included, the compiler says: Loading inherited module 'com.thoughtworks.xstream' [ERROR] Unable to find 'com/thoughtworks/xstream.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
Darren
Ok, i'm not a GWT expert, but i think the jar would need to have the source (needed by the GWT compiler) and the xml file. See this blog (http://roberthanson.blogspot.com/2006/05/how-to-package-gwt-components.html) for more info.
jon hanson
+1  A: 

GWT compiles Java source to JavaScript. You can´t just point to a regular jar. If you really must use XStream, you will need to include the sources under the client package or create a separate module and import it.

But for me this is just reinvent the wheel. You will have a lot of work and it will be slower than RPC. Even if there are other clients using the XML output, maybe you should consider having both ways.

ciczan