Background

So I decided to learn Java ME development. And I came across a blog called - well what do you know - the Java ME Blog, over at http://www.javameblog.com/.  Using the info on this blog along with what I found on the awesome java.net (http://today.java.net/pub/a/today/2005/02/09/j2me1.html), I was able to write a small MIDlet, and build it. Ah, now to run it... Not so fast; I kept getting an error message along these lines:

Starting emulator in execution mode
java.io.IOException: java.io.IOException: No such file or directory
   at java.lang.PosixProcess.<init>(libgcj.so.81)
   at java.lang.Runtime.execInternal(libgcj.so.81)
   at java.lang.Runtime.exec(libgcj.so.81)
   at java.lang.Runtime.exec(libgcj.so.81)
   at com.sun.kvem.environment.JVM.run(Unknown Source)
   at com.sun.kvem.environment.EmulatorInvoker.runEmulatorOtherVM(Unknown Source)
   at com.sun.kvem.environment.EmulatorInvoker.runEmulator(Unknown Source)
   at com.sun.kvem.environment.ProfileEnvironment$KVMThread.runEmulator(Unknown Source)
   at com.sun.kvem.environment.ProfileEnvironment$KVMThread.run(Unknown Source)
Caused by: java.io.IOException: No such file or directory
   at java.lang.PosixProcess.nativeSpawn(libgcj.so.81)
   at java.lang.PosixProcess.spawn(libgcj.so.81)
   at java.lang.PosixProcess$ProcessManager.run(libgcj.so.81)

After about 2 hrs of head-scratching and forum-and-mailing-list-hopping, I found two methods to solve the problem. They are explained below:

Method 1 - the hard way

Configuring default JDK on your Kubuntu Hardy box

To make Kubuntu recognize your jdk (JVM), use the update-alternatives command and issue following 3 commands one after another:
sudo update-alternatives --install /usr/bin/java java <JDK_INSTALL_PATH_HERE>/bin/java 100
sudo update-alternatives --install /usr/bin/jar jar <JDK_INSTALL_PATH_HERE>/bin/jar 100
sudo update-alternatives --install /usr/bin/javac javac <JDK_INSTALL_PATH_HERE>/bin/javac 100

These 3 commands set your java, jar and javac commands. You can use same to set other java executables if you want.

Now running sudo update-alternatives --config java will give you a choice between the JDKs available on your machine and you can (if it doesn't already have a * next to it)
set the Sun JDK as your default. Running java -version should give you an output similar to this:

java version "1.6.0_05"
Java(TM) SE Runtime Environment (build 1.6.0_05-b13)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)

HOORAY!! You're good to go. Running your application will now go smoothly.

Method 2 - The easy way

This method is cool because you don't have to change your system settings.
1. Open the file <NETBEANS_INSTALL_DIRECTORY>/mobility<WTK_VERSION>/bin/emulator in your favourite text editor ( ala nano, kate, vi, etc)
2. About the 3rd line you will find a line similar to
    javapathtowtk=
    Change that line to
    javapathtowtk=<JDK_INSTALL_PATH>/bin/

And you're done! Did you expect more? Sorry. Nothing to see here... Move right along and run your app. Now you will see a cool emulator phone on your screen.

Well that's all for now folks. More tips coming soon.

Signing out - Tash.

References:
http://today.java.net/pub/a/today/2005/02/09/j2me1.html
http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/