Multiple Projects and GWT

When work­ing on sev­er­al large scale projects (in Eclipse), it’s con­ve­nient and of course more effi­cient to share and reuse code via com­mon libraries. While those are in an ear­ly stage they need to be changed a lot and there­fore it’s handy to link projects in instead of cre­at­ing new jars each time the library has been updat­ed.
Unfor­tu­nate­ly, this stan­dard approach for Java devel­op­ment in Eclipse does not work that straight for­ward as with plain old Java projects, it requires three steps in total:

  1. Link the library project to all rel­e­vant projects (“Project Pref­er­ences” -> “Java Build Path” -> “Projects” -> “Add…”)
  2. Then, add the client-side code of the library (by adding it as a mod­ule.) There­fore, edit the gwt.xml of your appli­ca­tion and add for exam­ple <inherits name="net.svenbuschbeck.gwt.lib.SuperLib "/> where Super­Lib is the file name of the gwt.xml file in you library project and before that is the pack­age it lies in.
  3. Add the code to the project by link­ing a source fold­er. Unfor­tu­nate­ly, this is required if you do not want to write an Ant script to com­pile your appli­ca­tion. (If you prefer Ant check this out) I don’t like the idea of using such a script because if you for­get to run it each time you make changes, you will end up in confusion—let’s go for the con­ve­nient, auto­mat­ic way then. 
    1. Add a fold­er to your appli­ca­tion project; open the “advanced” sec­tion in the fold­er cre­ation dialog, select “Link to alter­nate loca­tion” and pick the source fold­er (usu­al­ly “src”) of your library project. (Hint: if you work with­in a team using a ver­sion­ing sys­tem, you can cre­ate a vari­able for that fold­er and use this instead. This way, each of your col­leagues can put the library project in a dif­fer­ent fold­er and accom­mo­date for that by adjust­ing the vari­able 🙂 )
    2. Right click the fold­er, “Build Path” -> “Use as Source Fold­er”. Done. 

Sur­pris­ing­ly, the GWT plug­in for Eclipse does not hon­or the project link­ing, thus all the ref­er­ences need to be made explic­it or you will end up with lots of the fol­low­ing: Class­Not­FoundEx­cep­tion.

Leave a Reply

Your email address will not be published. Required fields are marked *