How can I use a custom package structure in a GWT project?

122 Views Asked by At

I'm using the regular GWT project structure that is generated when creating a new GWT project via the Eclipse GWT plugin, e.g. com.mycompany.mygwtmodule.client for all the client stuff that is GWT-compiled into JavaScript.

Now I want to add some client code with a custom package structure, e.g. org.othercompany.somepackage...

Is that doable? And, if so, how?

I don't need a workaround, if it's not doable. However, it may still be helpful for you to know, why I want to do this: The custom package structure is from a 3rd-party GWT module that is used by my GWT project. I just need a small set of classes from it which I copied into my project instead of including the whole module which contains lots of stuff I don't care about. Those classes are using each other. As I do not want to touch their code at all, I am keeping their original package structure.

What I tried is to add <source path='my-eclipse-project-path/src/org/othercompany/somepackage'/> to my gwt.xml, but in hosted mode I'm getting the error: "No source code is available for type org.othercompany.somepackage.SomeClass; did you forget to inherit a required module?" No, I didn't ;-) The code is all there, but I couldn't make GWT find it.

Thanks for any helpful comments!

2

There are 2 best solutions below

1
On BEST ANSWER

Its Better you create two separate modules ,since you are taking the code from some other 3rd party jar. First create module which contain the package structure - com.mycompany.mygwtmodule (one module) Second create another module -org.othercompany.somepackage (another module)

Inherit the second module in first module.gwt.xml

 <inherits name="org.othercompany.somepackage" />
1
On

You need to add the other source package in your sources.

This is done in your module.gwt.xml. There is an element source, that will list all source packages to be included for client:

<source path="client" />
<source path="shared" />

will include all packages in client and shared into the frontend code.

Details can be found here: http://www.gwtproject.org/doc/latest/DevGuideOrganizingProjects.html#DevGuidePathFiltering

Update: if your packages have no common package you need to create two seperate modules and one inherits the other.

We use this a lot, it works out very nice.