tags:

views:

3083

answers:

6

I've got a GWT 1.6 project in Eclipse 3.4 and am trying to reference source from another (non-GWT) project in my workspace. I've added the project to my build path, but I can't run the application in hosted mode. When I do, I get a "no source code is available" error.

I've done some searching and reading and have tried a few things that others have suggested (including creating a jar from the dependent project and linking to it), but frankly nothing has worked.

If you're actually doing this, could you please help me out with a simple step-by-step setup? I'd really appreciate it, thanks!

A: 

GWT doesn't know about that other code because it is not in the client directory of your project. You need to add the source path for the other code to the .gwt.xml file. Just added it to the xml as follows

<source path="common" />

common is the directory where the extra code is for this example.

Check out the XML Element Reference section of this doc

Carnell
I've tried that. It then pukes saying that it can't find the entry point class (well, it just says it can't find type xxx.xxx.MyEntryPointClassType). The class is there. Everything works if I remove the dependent project and references.
Boden
You also need to make sure the client directory is added as a source path in the .gwt.xml file. For some reason if you add a custom source path the default client source path is not seen. So basically you need both the <source path="common" />and the <source path="client" />to get things working
Carnell
That's not working either... The only way I've gotten it to work thus far is to create a .gwt.xml module in the dependent project, create a jar from the source folder, and then "inherit" the module in the gwt project. This is far from ideal but sorta works.
Boden
I've tried making including the project, I've tried linking source, I've tried everything I can think of. I don't believe this is possible without using a jar.
Boden
A: 

The client-side code in your GWT project (the classes under the client package) can't reference any classes that aren't in a GWT module.

If you've got code in another project that you want to reference from client code in your GWT project, you need to:

  • Make sure it's all "GWT safe", which means it doesn't reference any JRE classes that aren't emulated by GWT (http://code.google.com/webtoolkit/doc/1.6/RefJreEmulation.html), or reference any classes that reference JRE classes not emulated
  • Make sure all referenced classes are within a GWT module. This means putting a MyOtherProject.gwt.xml file in your other project, and all the referenced classes must be under a client subpackage
  • Make your GWT project inherit from the other project. So add the following to your GWT project's gwt.xml module file:

<inherits name='com.yourCompany.otherProject.MyOtherProject' />

Steve Armstrong
Yeah... when I try it that way is when barfs finding the entry point. If I add the non-GWT project (containing a gwt module file) from my GWT project, it won't run. If I export a jar from that same dependent project and include it in my GWT application, it all runs ok.
Boden
Regarding the entry point. Did you check the Google -> Web Toolkit properties in the eclipse preferences. It's possible the specific gwt.xml is added to the Entry Point module list. Removing the file from the list should make it work.
Hilbrand
+1  A: 

Boden: add the following to your module file

<source path=""></source>

in addition to your other sources, eg:

<source path=""></source>
<source path="com.acme.otherpackage"></source>

then the compiler won't complain.

Atleast that's how I solved it. Not sure if using path="" allows inclusion of everything, I'm assuming it's the default value when no sources are specified.

+1  A: 

I have 2 Eclipse Projects. One is gwt project and one is not. Here's the directory structure that works for me:

workspace
-- gwt-project
   -- src/main/java
      -- com.gwt.GwtProjectModule
         -- GwtProjectModule.gwt.xml
-- non-gwt-project
   -- src/main/java
      -- com.nongwt.package.that.contains.source.you.need
         -- nongwt.gwt.xml
      -- com.nongwt.package.that.contains.source.you.need.client

nongwt.gwt.xml tells gwt to look inside "client" package, here's what it looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd"&gt;
<module rename-to='nongwt'>
    <inherits name='com.google.gwt.user.User' />
    <source path="client" />
</module>

GwtProjectModule.gwt.xml can then inherit source code from nongwt. Here's the relevant line from inside GwtProjectModule.gwt.xml:

<inherits name="com.nongwt.package.that.contains.source.you.need.nongwt" />

Make sure you include non-gwt-project inside gwt-project's classpath in eclipse. It's the normal drill; right click on gwt-project, choose properties, choose "Java Build Path", click "Projects" tab, and "non-gwt-project"

Or, instead of including non-gwt-project in gwt-project's classpath as a project reference, you can also jar the contents of non-gwt--project, ensure that you include the source in the jar, and then include the jar in gwt-project's classpath.

Good Luck!

Dave Paroulek
A: 

@Bert van Brakel: Thanks, this worked for me. If I was making a reusable GWT component I would probably create another .gwt.xml file and use the inherits tag. But since my external module is mostly just constants, using only the source tag is a nice lightweight solution.

z0r
A: 

in your gwt project, go to properties, java build path, source, click "link source" and point to your non-gwt project source package that you wish to include.

Luke