Wednesday, April 29, 2009

How to Deploy a GWT Application to Tomcat?

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.

Thursday, April 23, 2009

Developing for Android Platform

Why Android?
I'm a Java developer. Yes, I could enhance my C/C++ skills, get an iPhone and develop for the iDevices. But, I guess, I wasn't motivated enough. Also, I'm a strong supported of open source development. So, first, I noticed OpenMoko platform. But their development slowed down and stopped. Never got to the point when I'd be able to get a phone and develop for it. Finally, I noticed the Google's Android initiative in late 2007. Yes, I'm afraid of humongous corporations like Micstosoft and now Google. Still, I didn't see a more attractive choice. So, I waited for Google to release the Android phone. I could switch to Windows Mobile platform, but this, somehow, didn't attract me. Finally, in Jan 2009, after living with Palm for good 7 years, and I'm a heavy user of the personal organizers (several years ago, I'd create my own notebooks/calendars, so they'd fit my needs; out of paper and cardboard; I did this for good 2-3 years), finally in Jan 2009, I decided it was time to do the move and I purchased a black G1 (for the picture and a story of my other organizers, see this blog).

Does It Fulfill The Promise?
In short, yes. Is it perfect? No. I can suggest several improvements of the top of my head, even just for hardware. And for software, too, of course. Would I recommend it? Definitely. Does it have a potential? Oh, yes, sure. This section could be a topic on its own, but, it will have to wait for another time. Let's move.

So, to Cut To The Chase, How Do I Develop for Android
Simple. The list of tools I use:
  • Eclipse (3.4.2)
  • JDK (1.6)
  • ADT (0.8.0) - great tool. Can even deploy to the device over USB and monitor the app.
  • Positron aka Autoandroid - for integration testing. Unit testing doesn't work that great for fat clients. This is a great tool except for a few hick-ups.
  • jUnit - for the pieces that can be unit testing without reaching to your left year with your right foot.
Do you want more details, technical details? Sure. Here they're:

Where can I find some sample Android applications?
Well, one good sample is the Android platform itself. For example, to see the source code for the native Android calendar application, you can view it here.

Deploying onto the Device:
  • an unsigned .apk file installs with a "Application installation unsuccessful"
  • log a application crash,,, where can I find it? The ADT displays LogCat.

Using Positron aka Autoandroid:
  • If getting an error about Autoandroid " Connection reset" problem, either:
    • rerun the Android Application and run stories again or
    • application crashed on Android
  • If you get error "Internal Error ... ShouldNotReachHere", do
    • go to the jUnit relevant run configuration, //Classpath// and remove the Android Library from Bootstrap.
    • do //Advanced//, //Add Library// and choose JRE System Library
    • add JUnit library the same way