I fought with this for awhile, and finally figured out how to do this.
I hope it can help someone else as they progress through their own GWT
project.

The problem arises when you want to create a GWT application, but not
cram all your code in one huge monolithic GWT project. If you can
isolate functionality into modules, you are much better off. Plus, you
can let others make use of your hard work and contribute to GWT.

In my application, I needed user authentication/authorization, but I
certainly didn't want to put the code in my top level project. I
wanted it generic enough where it could be used by not only the
current project, but future endeavors. If I was writing a plain ol'
java application, its really a no-brainer; you create a separate
project, lets call it 'commons', and have your project to use the
commons project on its build path. GWT is almost this simple, but it
has a few gotchas that can drive you crazy.

My projects are a bit more complex than the following, but for the
sake of simplicity, lets say we have the following. I will highlight
the most important features.

I'm using the following. Hopefully my explanations of eclipse settings
are similar to yours.
 Mac OSX
 Eclipse v 3.4.1
 GWT v 1.7.0

loginmanager
  - an eclipse project
  - client folder: contains widgets like a LoginWidget,
AccountManagementWidget,etc. Listeners can be hooked up to a anonymous
event bus where you can receive notification about signin, signon,
account update, etc.
  - server folder: contains a servlet with signIn, signOut,
updateAccount, etc. Account persistence is in a mySQL database.
  WEB-INF/web.xml contains this among other things...
    <servlet>
      <servlet-name>LoginManager</servlet-name>
      <servlet-
class>org.reue.loginmanager.server.LoginManagerServiceImpl</servlet-
class>
    </servlet>

    <servlet-mapping>
      <servlet-name>LoginManager</servlet-name>
      <url-pattern>/loginmanager/login</url-pattern>
    </servlet-mapping>


I used the Eclipse GWT plugin, so I automatically get a
Loginmanager.gwt.xml file created for me. This works great when
developing this project module, but it will not work when you want to
use this module in another project. It contains an <entry-point> tag
that points to the class I used when I ran the module standalone
during its development.

Lets make  another module without the <entry-point>.
I called mine login.gwt.xml.
It contains the exact information as Loginmanager.gwt.xml, but does
not include the <entry-point>
Now i have

loginmanager
 -src
  -org.reue.loginmanager
   +client
   +server
   login.gwt.xml
   loginmanager.gwt.xml
...


MyApp
  - An eclipse project
  - I want to push a button and have the LoginWidget from the
loginmanager module show on the screen. I should be able to access the
anonymous event handler bus provided by the loginmanager module to
register myself as a listener for the events that my loginmanager
fires. I should not have to write any authentication/authorization/
persistence code.
  - client folder - contains MyApp.java which implements EntryPoint. I
just have a button that when pushed, instantiates a new LoginWidget,
provided by the loginmanager module, and shows it on the screen. I
will also register myself as a SignInHandler which is provided by my
module.
  - server folder - no server code

As you can see in this example, the application code is tiny. All the
work is done in the module. When I click the button, the LoginWidget
will show where I can enter my credentials and then click login. An
RPC call will be made to the servlet provided by the loginmanager
module, and I didnt have to write a single line of code as a user of
the module. (Obviously, one will have to create the MySQL database,
schema, etc) but the point here is that my application code is not
polluted by all the common authorization code.


Steps to get the MyApp project to properly inherit the loginmanager
module for design-time and runtime use:
1) Remember to create the extra *.gwt.xml file in your module so you
can inherit the module. Otherwise you will get complains of having
multiple entry points.
2) With the MyApp project selected, edit the build path
  Click: Project | Properties | Java Build Path
  Click the Projects tab
  Click the Add... button and add the loginmanager project
  Click the Source tab
  Click the Link Source... button
  The Link Source dialog shows
  For 'Linked Folder Location', Click Browse... and navigate to the
loginmanager project. You want the src folder here.
  For 'FolderName', you can give it any name you wish. I would just
name it after your module, like loginmanager.
  Click Finish
  Click OK on the Properties dialog
  In your Eclipse Package Explorer, you should now have 'loginmanager'
as a folder under your MyApp project

**Notes
When setting the build path of your app project, you must use the
'Link Source' option if your module contains any servlet code. This
was one of my main stumbling blocks. The LoginWidget would show up
fine, but when I clicked the login button, which made an RPC call, I
would get a ClassNotFoundException. If you do not link source, the
classes will in war/classes will not have your server code.

4) Inherit the module
  Edit your MyApp.gwt.xml file and add:
  <inherits name='org.reue.loginmanager.login'/>
    Remember we created the login.gwt.xml file in the loginmanager
module?

5) Configure the servlet that your module will use. You will need to
do this in 2 places, not just web.xml
  Edit your MyApp.gwt.xml file and add:
  <servlet path='/login'
class='org.reue.loginmanager.server.LoginManagerServiceImpl'/>
  Edit your web.xml and add:

  <servlet>
    <servlet-name>LoginManager</servlet-name>
    <servlet-
class>org.reue.loginmanager.server.LoginManagerServiceImpl</servlet-
class>
  </servlet>

  <servlet-mapping>
    <servlet-name>LoginManager</servlet-name>
    <url-pattern>/MyApp/login</url-pattern>
  </servlet-mapping>

**Notes
Notice how the url-pattern is different than the one that is in the
loginmanager web.xml version. You just have to prefix it with your app
not the loginmanager.

6) Add needed jar files to MyApp lib
Our loginmanager module made use of mysql and log4j, we need to add
those jars to our apps WEB-INF/lib directory

7) Disable use of the Google App Engine
If you are using jdbc, you may run into the error:
   java.security.AccessControlException: access denied
(java.lang.RuntimePermission modifyThreadGroup)

This can be resolved by, in Eclipse:
 Properties | Google | App Engine | <uncheck Use Google App Engine>

8) Thats it! You should now be able to use all the widgets in the
inherited module and have it work for you.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to