Building Java ME Apps with Modern Tooling
A step-by-step guide to building Java ME feature phone apps with OpenJDK 8, MicroEmulator stub JARs and ProGuard for preverification, without the old Sun SDKs.
Extract
Java ME (Micro Edition, also referred to as J2ME) is a platform for running Java applications on small resource constrained devices, such as feature phones from before the iPhone era. It is largely considered a dead platform with the advent of smartphones, and modern feature phones such as KaiOS use web technologies instead for their apps. However it is likely that you or someone you know have one of these old phones lying around, and you may be interested in how you can make Java apps that will run on it. This post goes through how to build a simple Java ME app solely with modern tooling in a modern environment, without needing anything from the old Sun Java ME SDKs. Requirements You will need some distribution of OpenJDK 8, such as the Temurin builds for various platforms. You should ideally make the binaries available on the PATH (and check that it’s the right version with java -version), for convenience. Also download MicroEmulator, because we will use their stub JARs that provides the Java ME APIs for compilation. Also download ProGuard (I use 7.1.1 for this), which will be used for the preverification step. The instructions in this blog post assume a Linux-y terminal environment, but you could also follow along with Git Bash or a similar environment on Windows. Hello World Here is a simple Hello World MIDlet that we will use. It will show a simple form using the LCDUI API with the text “Hello World!”: import javax.microedition.midlet.MIDlet; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Form; public class HelloMIDlet extends MIDlet { public void startApp() { Form form = new Form("Hello"); form.append("Hello World!"); Display.getDisplay(this).setCurrent(form); } public void pauseApp() {} public void destroyApp(boolean unconditional) {} } Save it as src/HelloMIDlet.java. Compile the class We will compile this with javac, but we first need the stub JARs from MicroEmulator available in the lib directory. Extract cldcapi11.jar and midpapi20.jar and put them in a lib directory next to the src directory. The cldcapi11.jar provides the CLDC 1.1 API and midpapi20.jar provides the MIDP 2.0 API. MIDP 2.0 is circa 2002, and is probably what you want to use for widest compatibility, while it has some important features that MIDP 1.0 lacks. Then we can compile the Java source file with the following command: mkdir -p build/classes javac -source 1.3 -target 1.1 -bootclasspath "lib/cldcapi11.jar:lib/midpapi20.jar"
-d …