Friday, June 24, 2011

Update Eclipse to use JDT Java 7 features

In a previous post, Eclipse java 7 support, I talked about the progress of java 7 related work in JDT. However, back then, there was no way of testing/using the java 7 features without downloading the relevant source code and launching another instance of Eclipse from that. The good news now is that it has become easier to use/test the java 7 features by updating Eclipse the P2 way i.e. "Install new software" option.

A wiki page tells you how to do that. So, go ahead enjoy JDT's java 7 features. Please file any bugs, or enhancement ideas you find/have in the compiler, content assist, code select and java search here with the [1.7] tag in the "Summary". This is still a work in progress and even though a lot of work has been done and several new compiler and UI options have been introduced for java 7, we're still working on new features and testing/improving the ones already implemented. More details about the state of the art are available on and

Note: This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and is made available for testing and evaluation purposes only. The code is not compatible with any specification of the JCP.

Thursday, June 2, 2011

Using PhoneGap in Eclipse to develop applications for Android or other mobile platforms

If you have been hearing a lot about this new kid on the mobile development block - PhoneGap (, and are as confused as I was when I started diving deeper, you've come to the right place to sort out your understanding a bit.

1)What is phonegap?

According to the website, "PhoneGap is an open source solution for building cross-platform mobile apps with modern, standards-based Web technologies. Based on HTML5, PhoneGap leverages web technologies developers already know best... HTML and JavaScript."
The definition itself does not make things very clear though. Let me explain a bit more. So today, suppose you have a web application that you want to deploy on multiple platform, say Android, iPhone, etc. In this app, you want to use one or more of the platform services to obtain some kind of data or carry out some kind of processing. Lets take, for example, an application that lets you invite friends to a movie as soon as you book a movie ticket. The app lets you select which friends to invite directly from your phone's contacts book. That means, if you're the developer of such an app, you'll most probably have to deal with consuming the platform's contact book using, for doing which, each platform would obviously have its own different ways. So there are 2 problems here:

1) How can you query the platform's contact book from within your web application which is being written in javascript(or Dojo) and has no knowledge of the platform's APIs.
2) How can you do so in a platform agnostic way, so that your web app works not just on Android but also on iPhone, notwithstanding the different ways of using the contacts book in both.

Phonegap aspires to be the answer to both of the above questions. How? It provides APIs which abstract the platform's contact book for you, so that you only deal with the Phonegap API and let phonegap do the rest of the magic for you.

2) How do I set up/install Phonegap on my system?

This one's not as trivial as a setup.exe, sadly! Phonegap requires a bunch of things to be installed on the machine before getting started. I found this document about installing phonegap - Unfortunately, I sat down doing all the steps and till a few hours, I was not even able to create my first phonegap hello world app.

So, the right thing to do here is to follow the above document till the "step 1f" i.e. install eclipse, android sdk, android development tools, apache ANT, and ruby. And you're almost done! Yes, don't get intimidated by the remaining steps in the doc. Step 2 onwards is a longer way of installing phoneGap and more relevant when you aren't going to use Eclipse. And that too, doesn't somehow work as stated. :(

Phonegap can be directly installed on Eclipseas a plugin. All you need to do is go to Help>Install new software>Add and use the download site "". Then making sure "contact all available update sites" is checked, install the phonegap plugin. Voila!  No need to download phonegap sources from github.

3) How do I create my first phonegap application?

On Eclipse, first create a new phonegap project by clicking on the phonegap comnand you see on the coolbar. Then if you don't have downloaded sources for phonegap, check

"Use Built-in PhoneGap" on the project wizard. Click Next and create the new Android project in the Android project wizard. (Note: You can also simply create an Android project, making sure that the android main activity class extends DroidGap class instead of Activity class. Make sure you add "phonegap.jar" as an external library to the build path.).

You see that a phonegap app is nothing but an android app with the main activity class extending phoneGap's droidgap class and it's onCreate method loading an html page instead of performing any native functionality. You can replace this html page by one of your own choice in the assets/www folder. Check out for some good examples.

You can now use the phonegap APIs such as the contacts API, media player API, geolocation API, etc. Ripple is a browser based emulator (a chrome extension) that you can use to test the PhoneGap applications. (Testing on the Android emulator is a bit slow with web apps).

Happy phonegapping!