Wednesday, April 29, 2009

How to Deploy a GWT Application to Tomcat?

Intro
OK, so you have tried the GWT (Google Web Toolkit), decided that it's cool, and you created your first application, precisely a module. You have tried it locally on your development machine, using the hosted mode and, may be, in the web mode by using the Compile/Browse button on the hosted-mode preview window. Now, you can either deploy it to Google App Engine, which is a way to try it online free and easily (make sure that your app doesn't become the IP of Google! I haven't looked at the terms of use myself.) or you decide yo want to go for it, and publish it for real. You purchase a Java hosting plan (google for it; you can find some within $12/mo.), and you're ready to deploy your application to your Tomcat server.

Deploying It
I used this re
source to help me with. Basically, follow the steps ( is the root of your GWT application,):
  • create a staging folder (let's call it deploy)
  • copy contents of /www/com.meography.EntryScreen into /deploy
  • create /WEB-INF with folders classes and lib in it
  • create web.xml file in WEB-INF. See the above resource for how to.
  • copy contents of /bin folder to deploy/WEB-INF/classes
  • copy all needed jars into deploy/WEB-INF/lib (you don't need gwt-user.jar nor gwt-dev-windows.jar, though)
  • compress all of the conents of deploy folder into a zip file and rename the file to .war.
  • upload the file to Tomcat, which can be done via browser using Tomcat manager, which is usually already installed for you by your Java hosting vendor. Once the upload finishes, the manager will show your application with options to Start, Stop, Reload and Undeploy it. The name of the app, is the base URL for your app.
Point your browser to the main .html file of the module (URL indicated by Tomcat manager + YourMainScreen.html). And, voila, you should be on. Well, if there are any problems, for example with your database setup, you'll find errors in the catalina.log file in the /tomcat/logs folder on your production server.

Re-Deploying It
To redeploy, after you have done some changes, simply repeat the steps above, but remember to preserve files you had to tweak or create for your production environment like web.xml and possibly hibernate.cfg.xml, if you happen to use Hibernate and use different database on your development machine and on your production server (Java hosting plan will usually have MySQL and PostgreSQL databases included). And, one more thing. I have found that I have to do Undeploy, upload the new .war file and then Deploy for the changes to post correctly. The reason may be, that GWT application is compiled into JavaScript cache files with random names, so the file names will be different each time you compile it, and so, just copying the new .war file over will not replace all of the old files.

Any feedback? Feel free to let me know.

3 comments:

Anonymous said...

Stan:

Looked for a way to email/contact you but failed ... So this will have to do.

I noticed at another site that you had a problem with Slogger/Firefox.

(The button not firing and TOOLS - SLOGGER RUN PROFILE/EDIT PROFILE not showing anything except a small box.)
I have the identical problem starting as of 03/07/09 - of course I didn't notice till today!

Have you found a solution?

Slogger was my life for storing web research!

If slogger is kaput is there a substitute? I've come acros an extension called 'Shelve'. Any opinions?

andrewconvery@doglegs.com

sabir said...

I was reading your blog about deploy GWT Application

I just finished my application; when I run my application in eclipse it works fine.

Then, I compiled the application by clicking the red icon ie 'GWT
Compile Project'. On settings, I picked 'log level'=all, and 'output
style'=detailed.

Finally, I get the message: Compilation succeeded -- 97.258s after a bunch of other lines.

Then, I took the content inside the 'war' folder and posted it online
using dreamweaver.

Clientside of the application works fine.
However, when I click on something that requires to get data from
server Implementation method, then it fails and I get the error:
com.google.gwt.user.client.rpc.StatusCodeException:

As for hosting server, my server has 'apache 2.2.11.' My computer also has WAMP with 'apache 2.2.11'.

Is there a way to deploy GWT application online with apache 2.2.11?

I am new to this, thanks for the support.

sam

stanb said...

Sorry for late reply. Haven't enabled the comment notifications. I haven't worked with GWT for a few months now, so I may be wrong, but don't you need a Java Application server like Tomcat, Glassfish, JBoss or another communicate with the server using the GWT "native" RPC protocol?
StanB