Search code examples
eclipsegwt

Eclipse 3.4 GWT 1.6 project - how to reference source from other projects?


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 nothing has worked.

What can I try next?


Solution

  • 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">
    <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!