views:

315

answers:

4

Hello

I have a GWT project. Client code is located in the "client" dir. I want to attach an external java classes (mainly plain POJO DTO classes) that are in external directory. How to configure the gwt.xml file?

I get errors of this kind:

[ERROR] Errors in 'file:/C:/development/projects/CodeSpaces/LocateMe/LocateMeWeb/src/com/dominolog/locateme/client/LocateMeWeb.java' [ERROR] Line 56: No source code is available for type com.dominolog.locateme.model.dto.LocationInfo; did you forget to inherit a required module?

A: 

Any Java classes to be used by GWT must have a module file and conform to a package structure that includes a sub package. See this stackoverflow answer for more details: Adding Java packages to GWT. In this case a module file (e.g. model.gwt.xml) could be created in the directory com.dominolog.locateme.model that contains the following content:

<module>
  <source path="dto" />
</module>

Add a reference to this module file in your main module file and GWT will then take all classes in the com.dominolog.locateme.model.dto package.

2 notes:

  1. GWT will look at all classes in the directory (and subdirectories)

  2. The classes in the package must be present in source files and may not contain any references to other libraries not parseable by GWT (This might be a limitation when in the dto classes annotations are used that refer to specific database usages).

Update: Rewritten answer to be more specific.

Hilbrand
Thanks but the post you refer to does not explain anything but that I have to add all my code under the client directory. This is not acceptable for me.
dominolog
I'll try to be more specific. My workspace structure is:Workspace-> LocateMeModel LocateMeServer LocateMeMobile LocateMeWebThe LocateMeWeb is a GWT application with standard project layout. In LocateMeModel I have Java classes that define dto (data transfer objects) that are common for LocateMeWeb, LocateMeMobile and LocateMeServer. Therefore, I need that GWT takes files from this directory (LocateMeModel) and compiles it as a client code. Is it possible at all? From what I see GWT allows only that the code MUST BE under client directory with GWT project.
dominolog
+2  A: 

If you have the java source files you just need to add the directory to you .gwt.xml file. For instance if you had a subdirectory called shared you would add the following line:

<source path='shared'/>

The folder called shared would have to be one level under your main package. So if you project .gwt.xml file is at com.yourdomain.project the shared folder.package would be com.yourdomain.project.shared. Refer to the Source Path section at http://code.google.com/webtoolkit/doc/latest/DevGuideOrganizingProjects.html#DevGuideModules

If you dont have the source and only have the classes you have to import a module as Hilbrand has stated.

Carnell
Ok. But what if the code I want to add is not under "client" ie it is an external directory within my workspace?
dominolog
Is it in the same project? If so I assume it starts with the same package (com.yourdomain.project in my example) and what I have outlined will work. It does not need to be under client. If its coming from another source/project I don't know how/if you can add it to the project.
Carnell
A: 

I'll try to be more specific. My workspace structure is: Workspace

  1. LocateMeModel
  2. LocateMeServer
  3. LocateMeMobile
  4. LocateMeWeb

The LocateMeWeb is a GWT application with standard project layout. In LocateMeModel I have Java classes that define dto (data transfer objects) that are common for LocateMeWeb, LocateMeMobile and LocateMeServer. Therefore, I need that GWT takes files from this directory (LocateMeModel) and compiles it as a client code. Is it possible at all? From what I see GWT allows only that the code MUST BE under client directory with GWT project.

dominolog
A: 

I have found solution there

dominolog