Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Java packages to GWT

I've tried searching but couldn't come up with a defined way on how to add your own packages to a GWT project.

My tree structure looks like this:

-com.mycompany
  -public
    MyApplication.html
  MyApplication.gwt.xml


-com.mycompany.client
  MyApp.java

-com.mycompany.gui
  TableLayout.java

The answer I've seen out there says to add the packages relative to the root directory of the gwt.xml file, like so:

<module>
  <inherits name="com.google.gwt.user.User" />
  <entry-point class="com.mycompany.client.MyApp" />
  <source path="client" />
  <source path="gui" />
</module>

It then complains:

Unable to find type 'com.technicon.client.MyApp'
   Hint: Previous compiler errors may have made this type unavailable
   Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly

Can anyone tell me what I'm doing wrong and how to fix this?

like image 951
Organiccat Avatar asked Jan 13 '09 17:01

Organiccat


Video Answer


2 Answers

even though, as @rustyshelf pointed out, gwt will convert everything that is under client.* automatically, there will be times when you will want to keep things outside of your client packages (reusing them in several project might be one of them) and for that the solution still resides in adding other packages to the process using the source element.

now there is a trick, you have to decide whether you want to move the gwt.xml config file or whether you need to create a new one.

for your case in particular (where both packages share a root in the package, com.mycompany) you can just move the <project_name>.gwt.xml file to the top most common package and just add the new package as a source (and keeping the <source path="client"/> there as well) thus making your file to look like:

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

on the other hand if the packages don't share any root, just create a new *.gwt.xml file with only the source elements and place it on a parent package to the sub-package you want to add, i.e:

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

note that if you need to give compilation-access to nested sub-packages do so by separating them with a / like in "admin/client"

hope this help you get back on track and organize your code the best way possible.

like image 110
samiq Avatar answered Oct 20 '22 13:10

samiq


You can get rid of the two source path lines, because by default GWT will pick up anything that is relative to the root, and in the client package like you have. You also need to move your gui package into your client package, so it would become:

-com.mycompany
  -public
    MyApplication.html
  MyApplication.gwt.xml


-com.mycompany.client
  MyApp.java

-com.mycompany.client.gui
  TableLayout.java


<module>
  <inherits name="com.google.gwt.user.User" />
  <entry-point class="com.mycompany.client.MyApp" />
</module>

Assuming your MyApp.java is an actual EntryPoint, then this should work just fine.

One other thing to note is that you cannot use java classes that are not part of the GWT JRE Emulation library, and your project won't compile if you do. You should get very specific errors about this though. For example you cannot use library classes like java.math.BigDecimal, if they are not emulated. All of your own classes you create can be used though.

like image 44
rustyshelf Avatar answered Oct 20 '22 13:10

rustyshelf