Java ME Debugging

Connected Limited Device Configuration

These instructions are written to the CLDC 1.1 reference implementation available from Sun Microsytems. The steps outlined here may be different on other Java Micro Edition platforms. You should be using the latest version of JSwat, as older versions had problems with debugging implementations of the CLDC.

To enable debugging, the KVM must be started via the kvm_g executable, and you need to pass the -debugger option. Here is an example, run from the j2me_cldc directory of the CLDC reference implementation, on a Linux system:

./bin/linux/debug/kvm_g -debugger -classpath bin/common/api/classes:samples/classes HelloWorld

This assumes that you have created HelloWorld.java, placed it in samples/classes, and compiled it with the command javac -g HelloWorld.java in order to compile the class with the debugging information included. When compiling, you may find that the 1.5 version of the JDK will generate byte code newer than what the CLDC implementation expects. In this case, use an older version of the JDK, such as 1.3 or 1.4.

Because the KVM does not implement the entire JPDA feature set, a debug agent, or proxy, is needed. In the CLDC reference implementation this is called the KDP and must be started from another command shell in the j2me_cldc directory:

java -classpath bin/common/tools/kdp/classes kdp.KVMDebugProxy -l 5000 -p -cp samples/classes:bin/common/api/classes

Now you may start JSwat and connect to port 5000 using the Attach dialog. From here you should be able to debug in the usual manner. If the debugger appears to freeze at any point, terminating the kdp process will most likely restore it to normal.

Java Wireless Toolkit

The Java Wireless Toolkit is a more developed form of the CLDC which includes MIDP and a graphical interface for managing MIDlets, the Java applications deployed to a Java-enabled device.

To use JSwat with the Wireless Toolkit, you must first start the ktoolbar program and open your MIDlet project. From here, select the Debug menu item from the Project menu. In the dialog that appears, accept the default value of 5000 for the port number, and click the Debug button. At this point you should start JSwat and use the Attach dialog to connect to port 5000. If that succeeded, you may debug your MIDlet in the usual manner.