how to share a class across packages/modules

GWT Designer allows you to quickly create the modules, composites, panels, remote services and other elements that comprise Google Web Tookit applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

how to share a class across packages/modules

Postby xristy » Fri Aug 15, 2008 11:13 am

Hello,

I'm not sure if this is a GWT-Designer issue or just a GWT issue. I did post this on the GWT developers list but got zero responses. So maybe it was mis-posted or maybe it just doesn't make any sense. In any event, I'm using GWT 1.5.1 (Mac OS X 10.5.4) with GWT-Designer 5.1.0 in Eclipse 3.4.

I have a Class of utility methods and other definitions that I want to
share across several different packages implementing GWT modules. The
Utils.java work fine if it is defined in the *.client.* package with
the other classes that reference it.

I am not able to move the Utils.java higher in the package structure
without either getting an error when I run in the hosted environment
or during build-time in eclipse.

The package structure is like:

Code: Select all
org.tbrc.gwt.
   Queries.java
   Utils.java
   person.
       PersonViewer.gwt.xml
       client.
           PersonViewer.java
       server.
   work.
       WorkViewer.gwt.xml
       client.
           WorkViewer.java
       server.


So I have added to PersonViewer.gwt.xml and WorkViewer.gwt.xml:

Code: Select all
   <inherits name="org.tbrc.gwt.Utils"/>


and I have added org/tbrc/Utils.gwt.xml:

Code: Select all
<module>
</module>


As described this builds fine in the eclipse configuration with GWT-
Designer and such but when I run in hosted mode I get:

[ERROR] Unable to find 'org/tbrc/gwt/Utils.gwt.xml' on your classpath;
could be a typo, or maybe you forgot to include a classpath entry for
source?


But if I put Utils.gwt.xml at 'org/tbrc/gwt/Utils.gwt.xml' then I get
a build-time error:

org.tbrc.gwt.Utils cannot be found in source packages. Check the
inheritance chain from your module; ...


I would appreciate any help on how to properly organize code to enable
such sharing. Obviously it is possible since the the GWT environment
appears to be based on such. I looked at some of the GWT source but
nothing popped out as the explanation of how to approach such sharing.

Hopefully what I am trying to do is clear.

Thank you,
Chris
xristy
 
Posts: 33
Joined: Mon Aug 04, 2008 5:31 am

Re: how to share a class across packages/modules

Postby Eric Clayberg » Sat Aug 16, 2008 4:24 am

Have you tried creating a GWT Library module and then creating the shared classes in its "client" package?

Image
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: how to share a class across packages/modules

Postby xristy » Sat Aug 16, 2008 5:21 am

Dear Eric,

Thank you very much for your kind assistance. The GWT Library Module is really the kind of solution that I wanted in the first place. I had not noticed the section on "Instructions for creating a common shareable widget library project" at the bottom of the page for GWT Project Creation. Maybe it could have its own heading in the TOC.

Being new to GWT, one thing that I have not found a lot of information on is this sort of global project organizational approach and so on.

Again, thank you,
Chris
xristy
 
Posts: 33
Joined: Mon Aug 04, 2008 5:31 am

Re: how to share a class across packages/modules

Postby Eric Clayberg » Sat Aug 16, 2008 8:06 am

xristy wrote:The GWT Library Module is really the kind of solution that I wanted in the first place.

I'm glad that worked for you.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: how to share a class across packages/modules

Postby mons » Thu Sep 18, 2008 3:47 am

Im also facing the same problem. i tried with library module also but still the error exists.
May be im not doing in the right way. can anyone tell me the proper steps to do it?
mons
 
Posts: 1
Joined: Thu Sep 18, 2008 3:26 am

Re: how to share a class across packages/modules

Postby Eric Clayberg » Thu Sep 18, 2008 5:04 am

mons wrote:Im also facing the same problem. i tried with library module also but still the error exists.
May be im not doing in the right way. can anyone tell me the proper steps to do it?

The best place to ask general GWT-related questions is Google's GWT forum.

The most likely problem is that you created a shareable GWT module, but then forgot to import/inherit it into your "main" GWT module.

The simplest way to import it is to try use any class from the shareable module, save and then use our quick fix to generate the import.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to GWT Designer

Who is online

Users browsing this forum: No registered users and 3 guests