Developing for Mobiles with Java on Ubuntu
Mobile devices are getting more and more powerful, if you get a mobile phone the odds are it will not just be a phone but a camera, organiser, music player, video player and web browser too. You can also extend the capabilities of you phone by downloading applications and games to it. One of the most significant aspects of this is that we are talking about technology that many people already own, not just-released or niche devices, so there is a sizeable potential audience for new applications. There are a vast array of mobile phones out there, each running their own operating system and with different ways of programming them. One thing is common to many of these devices though: Java, Micro Edition (also known as Java ME and J2ME), a version of the platform-independent Java language optimised for mobile devices. You can write applications using Java and the same application on many different types of devices, you don't have to worry about the specifics of the hardware, which might be just as well as models of mobile phone come and go very quickly. You can set up a fully featured development environment for Java Mobile on your Ubuntu machine, gain access to this very popular platform and create the next ground-breaking application for mobile devices!
I've set up a full development environment for Java ME on my Ubuntu machine that includes a compiler toolset, phone emulators (the Sun Java Wireless Toolkit), an IDE (Eclipse) and IDE plugin for Java mobile development ( Mobile Tools for Java). The method is slightly manual, and an extra step is required if, like me, you are using the 64bit version of Ubuntu.
The first step is to install a Java Development Kit (JDK) this is a toolset that can turn Java programs into platform-neutral code. You should install the default-jdk package in Ubuntu (if you find this does not work very well for you try sun-java6-jdk). If you are using the 64 bit version of Ubuntu, unfortunately we have an added complication that the Sun Java Wireless Toolkit only seems to work with a 32 bit Java compiler, so you will additionally need to download this from http://java.sun.com, run the downloaded file from a terminal window and install it to somewhere it can be easily found, e.g. /opt/jdk32.
Now you can download the Sun Java Wireless Toolkit (WTK) from http://java.sun.com/products/sjwtoolkit/, this will be a self extracting archive, ending in the extension “bin”. In a terminal window go to the directory containing the download and run it by typing ./sun_java_wireless_toolkit-2_5_2-linux.bin, if you cannon run it make sure the execute permission is set (set it with chmod u+x sun_java_wireless_toolkit-2_5_2-linux.bin). A text installer will come up asking you for certain bits of information, if you are on 64 bit Ubuntu remember to put in the path of your manually installed 32bit JDK. Install the WTK to /opt in order to find it easily again. You might want to add an entry to the Ubuntu menu for the WTK, this can be done by going to System → Preferences → Main Menu and making a new entry under Programming. You can find images to use as an icon under /opt/WTK2.5.2/wtklib/images/.
Next task is to grab a completely up-to-date version of the Eclipse IDE. There is a version of this in the Ubuntu repositories, but it is not completely up-to-date, so I opted to download a copy from http://www.eclipse.org/downloads/ selecting the version entitled Eclipse IDE for Java Developers. It can be installed just by extracting it from the downloaded archive file and placing it under /opt/eclipse. Again, you can make an entry in the Ubuntu menu system using Main Menu, an icon was a bit tricky to track down, but can be found at: /opt/eclipse/plugins/org.eclipse.platform_3.3.101.v200809111700/eclipse48.png.
With the WTK and Eclipse in place, we now need something to integrate the two; that something is the Mobile Tools for Java project, a plugin that connects Eclipse to the WTK and provides the features of the WTK from inside Eclipse itself. The best way to install this is though its update site, which Eclipse can periodically check for updates. In Eclipse go to Help → Software Updates → Available Software and click on Add Site. To find the right site name to add have a look at http://www.eclipse.org/dsdp/mtj/download/update.php and copy/paste the entry for the “Releases” entry for the location. Once added, you should see an option to add plugins from that site in the left hand side of the Available Software window. Click the entries under this heading and click Install. The final step is to configure the plugin, go to Window → Preferences → Java ME. In WTK Root enter: /opt/WTK2.5.2 and in Device Management in the left pane, you may need to import the phone emulators. Do this by clicking Import and browsing to your WTK location.
Everything you need to develop Java ME applications is now installed. If you are not familiar with the Java language, Sun have a New to Java website with tutorials at: http://java.sun.com/new2java/learning/index.jsp. A “Hello World” tutorial for Java ME is available on linux.com at: http://www.linux.com/feature/122050. Plenty of books are available on Java and Java ME too including Beginning Java ME by Apress, which I have the previous edition of and seems pretty good so far. This is only one of the options to develop Java ME applications on Ubuntu, you could for example also use the Netbeans Mobility Pack, which looks very interesting, and hopefully I'll be blogging about soon. As both Eclipse and Netbeans are free you could always try them both out to see which you like best, without any risk.