GWT Warning “Non-canonical source package”

The Problem

Sometimes you might want to include classes from a package in your gwt module, which are not in a sub-package of the package in which you have defined the Gwt module (MyModule.gwt.xml).

For instance, you might have the following directory structure:

/client/ClientService.java

/browser/BrowserEntryPoint.java

/browser/MyModule.gwt.xml

The first natural option would be to define a source dependency in the Gwt module (gwt.xml) as follows:

<source path=’../client’ />

However, when compiling the module, a “Non-canonical source package” warning is issued. Furthermore, the class in the client package will not be recognized by the Gwt compiler.

The Solution

One clean (but not necessary straightforward) solution is to define a new Gwt module in the client package, and link this in your original module. The directory structure would change to:

/client/ClientService.java

/client/ClientModule.gwt.xml

/browser/BrowserEntryPoint.java

/browser/MyModule.gwt.xml

The following dependency would have to be added to MyModule.gwt.xml:

<inherits name=’client.ClientModule’></inherits>

Resources

GWT Google Group – Source-Source

 

2 thoughts on “GWT Warning “Non-canonical source package”

    1. ClientModule.gwt.xml can just be a default module definition such as:

      <module rename-to="ClientModule">
      <inherits name="com.google.gwt.user.User" />
      <entry-point class="client.DummyEntryPoint" />
      </module>

      (please note you might need to add inherits as well)

      Hope this helps.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s