JVM and SWT

Getting Started

Preliminaries

Make sure you understand how to do the following things:

  1. Become root on the device
  2. ssh into the device

For more information on these steps, please refer to http://www.arachnoid.com/linux/nokia/ for instructions.

Get Device IP address

In order to ssh into the device, you need to get the IP address. This can be achieved as follows (assuming you are already connected to a network):

  1. Open X Terminal. This should be installed in OS2008 under Application Manager → Utilities → X terminal.
  2. Become root, then use the ifconfig command to get the inet addr:xxx.xxx.xx.xx for wlan0. Point your ssh client to this address.

Red Pill Mode

It will be necessary to enter into the “Red Pill Mode” in the Application Manager to install Cacao and GNU Classpath (described later). To do this:

  1. Open the Application Manager
  2. Go to Tools (the drop down menu in the upper left corner of the display) → Application Catalog
  3. Click on “New”
  4. In the web address field enter “matrix”
  5. Hit the “Cancel” button
  6. Select “Red” to activate Red Pill mode (Selecting blue deactivates it)
  7. Close the Application Catalog

Install Jalimo

Jalimo (Java Linux Mobile Platform, https://wiki.evolvis.org/jalimo/index.php/Jalimo) is a project to maintain a full featured free Java-like stack for mobile Linux-based devices, with support for Maemo. Jalimo does not support Swing, but fully supports Eclipse SWT.

For basic Java functionality, simply click on the following link on the device: http://jalimo.evolvis.org/repository/maemo/jalimo-swt-example-install.php. This link installs:

  1. Cacao (a JVM)
  2. GNU Classpath (a free software implementation of the standard class library)
  3. Eclipse SWT jars (an open source widget toolkit for Java)
  4. jalimo-swt-example (an example SWT application)

Select “Open” from the dialog box in order to launch the Application Manager and automatically install the necessary components of Jalimo. Click “OK” through the remaining dialog screens. Assuming things go smoothly, you should now be able to run the installed SWT example file, located at: Application Manager→ Extras→ Jalimo SWT Example.

For Java application development, Jalimo recommends installation from following link on the device while in red pill mode: http://jalimo.evolvis.org/repository/maemo/jalimo-install.php. Interestingly, this install package is the same as the previous package except that it does not include SWT. Therefore we recommend using the first install.

You are now ready to develop your first application.

Test the Installation

In this section, we will demonstrate how to develop a simple “Hello World” application. Using your favorite text editor on your computer, create a file named HelloWorld.java, and enter the following text:

public class HelloWorld {
     public static void main(String[] args) {
          System.out.println("Hello World");
     }
}

Important: You must create the .class files for the application on your own computer. Jalimo does not include a java compiler on the phone. After compiling, copy HelloWorld.class over to the device (via ssh, for example). To run the application:

  1. Open X Terminal on the device and browse to the folder which contains HelloWorld.class
  2. Use the cacao command with the name of the class file:
cacao HelloWorld

Alternatively, the java command appears to work as well:

java HelloWorld

It is also worth mentioning that although applications can be developed outside of scratchbox, there are some minor differences between the Sun JVM and Cacao. For development in scratchbox, visit: https://wiki.evolvis.org/jalimo/index.php/Maemo_Jalimo_SDK

Note, do not include the .class extension. You should now see “Hello World” output to X Terminal. Alternatively, you can run the cacao (or java) command on the device via ssh.

SWT Example

To develop Java applications with simple graphics objects which can be run on the device, you may consider using Eclipse IDE with SWT installed. Assuming you already have Eclipse (available here http://www.eclipse.org/), you can add SWT by visiting http://www.eclipse.org/swt/ and click on the appropriate download link for your operating system. Complete instructions for installation and developing SWT applications in Eclipse can be found here: http://www.eclipse.org/swt/eclipse.php.

Create the following SimpleSwtSample.java on your computer:

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.*;
 
public class SimpleSwtSample {
 
	public static void main(String[] args) {
		Display display = Display.getDefault();
		final Shell shell = new Shell(display);
		shell.setLayout(new RowLayout(SWT.VERTICAL));
 
		Label label = new Label(shell, SWT.CENTER);
		label.setText("Hello maemo");
 
		Button button = new Button(shell, SWT.NONE);
		button.setText("close");
		button.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event arg0) {
				shell.dispose();
			}
		});
 
		shell.open();		
		while (!shell.isDisposed())
			display.readAndDispatch();
	}
}

Compile on your computer, and copy SimpleSwtSample.class to the device. Finally, in X Terminal on the device, run:

cacao -cp /usr/share/java/swt-gtk.jar SimpleSwtSample

Other Examples

Server/Client

We have tested jalimo for a simple echo server and a client. The files can be downloaded from http://www.cs.berkeley.edu/~pallavi/docs/Java.tar.gz. To run the server, do 'java SimpleServer' and then to run the client do 'java SimpleClient' from another X terminal.

Multithread

We tested jalimo with a simple multithreaded example too. The example can be downloaded from http://www.cs.berkeley.edu/~pallavi/docs/Java.tar.gz. The example spawns a thread which prints some messages. To run the example, do 'java SimpleThreads'.

JNI

We tried running simple JNI examples (as the ones from Sun's Java tutorials), but either the VM crashes with a segmentation fault or it erroneously reports it cannot find the library in its classpath (even if the library is in fact there). JNI doesn't work at all in Scratchbox.

We're currently trying to replicate the software stack of ECJ + GNU Classpath + Cacao VM on a regular machine and see what's happening; the latest Cacaco release has a bug that prevents it from compiling with JNI enabled, while the version from the Mercurial repository builds but always segfaults. We're hoping to get some feedback from the Jalimo developer community.

Useful Links

 
shortproject/jvm.txt · Last modified: 2008/03/18 15:32 by dbwork
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki