tags:

views:

3328

answers:

3

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?

+2  A: 

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.

rustyshelf
A: 

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.

samiq
A: 

i takes same error again i want to use openid4java i put *.jar about openid and i give it as built path i writed

dene6.java

import org.openid4java.message.AuthRequest; import com.extjs.gxt.ui.client.widget.form.TextField; import com.google.gwt.core.client.EntryPoint; public class Dene6 implements EntryPoint { public void onModuleLoad() { AuthRequest as; TextField ass = new TextField(); RootPanel.get().add(ass);}}

this is my dene6.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='dene6'>
  <inherits name='com.google.gwt.user.User'/>
<inherits name='com.extjs.gxt.ui.GXT'></inherits>
  <inherits name='com.google.gwt.user.theme.standard.Standard'/>
  <entry-point class='dene.client.Dene6'/>
  <source path='client'/>
  <source path='shared'/>

when onModuleLoad() start its give

   16:56:13.622 [DEBUG] [dene6] Validating newly compiled units
    16:56:13.628 [ERROR] [dene6] Errors in 'file:/C:/Users/BNYMN/workspace/dene6/src/dene/client/Dene6.java'
    16:56:13.654 [ERROR] [dene6] Line 31: No source code is available for type org.openid4java.message.AuthRequest; did you forget to inherit a required module?
    16:56:15.454 [TRACE] [dene6] Finding entry point classes
    16:56:15.459 [ERROR] [dene6] Unable to find type 'dene.client.Dene6'
    16:56:15.476 [ERROR] [dene6] Hint: Previous compiler errors may have made this type unavailable
    16:56:15.495 [ERROR] [dene6] 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
    16:56:15.514 [ERROR] [dene6] Failed to load module 'dene6' from user agent 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3' at 127.0.0.1:53236

can someone help me pls?