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
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
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.
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:
<inherits name='com.yourCompany.otherProject.MyOtherProject' />
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.
Edit: Found a eclipse fix. Run config > Classpath > Advanced > Add folder > otherproject/src .
Reason: Eclipse adds the bin folders of exported projects. GWT needs the src folders.
Elaborating on my comment.
I am using gwt 2.8 on Eclipse Neon, Java 1.8.0_92. Referring to another project in eclipse fails to launch devmode, because it cannot find the source for referred files from the other project.
What worked:
Switched to 'ant devmode' completely. Made the following changes to build.xml:
<target name="gwtc" ...>
<java ...>
<classpath>
<pathelement location="src"/>
<pathelement location="../otherproject/src"/><!-- Added -->
...
...
<target name="devmode" ...>
<java ...>
<classpath>
<pathelement location="src"/>
<pathelement location="../otherproject/src"/><!-- Added -->
Now do a production build with 'ant' or start devmode with 'ant devmode'.
Other things I noticed
Using the method in the accepted answer, otherproject/src/foo.gwt.xml is picked up (complains if not available), and static values from classes are picked up. Nothing else is. Very weird.
I understand that the DevMode/gwtc executables pick up sources from their class path. So all that is needed is for eclipse to add referred projects to their class path. I was not able to achieve this but this seems possible. FIXED see top.
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!