行云小站
Say hello to you!
图片来自 @Unsplash
w568w 创建时间被隐藏
[EN] Notes on Java ME Development in 2024
本文已被读

Photo by <a href=https://unsplash.com/@wtrsnvc?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash>wtrsnvc _</a> on <a href=https://unsplash.com/photos/a-cell-phone-sitting-on-top-of-a-table-EE7NvZ9klZo?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash>Unsplash</a>

1. History Time (Skip if not interested)

1.1. The Rise of Java ME, and…

Back in 2001, game developers gathered at the JavaOne conference in San Francisco to hear about the latest in Java technology, where they saw a famous hedgehog running on a mobile phone screen, moving faster than anything they had ever seen before. This was the first time that Java ME was introduced to the world, and as Gameloft put it, “a revolution was coming”.

In the next couple of years, this technology would bring us some of the most iconic games in the history of mobile gaming, such as the famous Snake game on Nokia phones, Prince of Persia, and the legendary Asphalt series. It was such a huge success that old protocols like WAP and Qualcomm’s BREW1 were quickly forgotten, and Java ME became the standard for mobile game development. In 2013, there were over 3 billion devices running Java ME. From Nokia to Sony Ericsson, from Motorola to Samsung, every phone manufacturer was advertising their Java ME compatibility.

Java ME consists of two profiles:

  1. CLDC (Connected Limited Device Configuration), which defines the minimum language features and libraries that a Java ME device must have, and
  2. MIDP (Mobile Information Device Profile), which defines the APIs to manipulate the device’s GUI, messaging and storage capabilities.

Besides, most devices also support the JSR (Java Specification Requests) APIs and their own proprietary APIs (Nokia, Samsung, Siemens, and Sprint to name a few) to extend the capabilities of bluetooth, camera, 3D graphics, etc.

Currently, most J2ME phones you find are with MIDP 2.1 and CLDC 1.1, which is the most common configuration for J2ME game developers. Both of them are published before 20062.

1.2. …the Fall of Java ME

The next big step in the mobile games market would come in 2007, Apple, at this point in time, was very successful, with their computers as the main commercial competitor to Microsoft’s Windows and their iPod brand being the biggest MP4 brand in the market, yet it was a fraction of what it is today. The iPhone was described then by Steve Jobs as “an iPod, a Phone and an internet communicator”, it was “not a smartphone” because those are “complicated to use” and the iPhone was meant for everyone, making it perfect for mobile games.

Not long after the release of the iPhone, Google would release their response, the Android was developed by the Open Handset Alliance, a consortium of firms from different fields mostly related to mobile phones, with its biggest contributor being Google. It was the open source version of what Apple was doing with the iPhone, the Linux to their OS X.3

The after story is well known, the iPhone and Android dominated the market, Windows Phone and BlackBerry OS rapidly lost market share, and Java ME was left behind. The last version of Java ME, Oracle Java ME 8.3, was released in 2018, and the last phone to support Java ME was said to be the Nokia 3310 3G, released in 2017.

2. How to Build a Java ME Game in 2024

Out of curiosity, I decided to try building a Java ME application a few days ago. Although most links and resources are no longer available, with some persistence, I managed to find a way to build it on my Windows 11 24H2 machine. Here’s a step-by-step guide.

2.1. Prerequisites

You need to meet the following system requirements:

  • Windows (any version, as long as you can run Oracle JDK 8), or
  • Linux (I haven’t tested it, but it should work)
  • 32-bit is better; 64-bit requires some extra steps to run the emulator

2.2. Install Oracle JDK 8

The Java ME SDK requires Oracle JDK to run, and it has only been officially tested with Oracle JDK 5. Since Oracle JDK 5 is no longer available, I installed Oracle JDK 8 instead. You can download it here.

2.3. Install Java ME SDK

Originally, the J2ME SDK was called “Java Wireless Toolkit (WTK)”, which was formly known as “J2ME Wireless Toolkit”, developed by Sun Microsystems. Later it was integrated into Oracle Java ME SDK 3.0.

Since our development tools don’t support Oracle Java ME SDK 8.3 and only have some partial support for Oracle Java ME SDK 8.0 (believe it or not, the previous version of 8.0 is 3.x!), and I’m very disappointed with the Java ME SDK after several failed attempts, I decided to use the old “Java Wireless Toolkit” instead. If you managed to get Oracle Java ME SDK 8.3 working, please let me know!

Google Sun Java Wireless Toolkit or just download it here.

Run the setup, select where the JDK 8 is installed, and install it to a directory, say, C:\WTK2.5.2_01.

2.4. Install Eclipse IDE

There are only two IDEs that support Java ME development: NetBeans and Eclipse. I chose Eclipse because it’s more lightweight and I’m more familiar with it.

However, the J2ME plugin for Eclipse is incompatible with the latest version of Eclipse, so you need to download an older version of Eclipse. To be specific, the lastest version that supports J2ME development is Eclipse 4.5 (Mars). You can download it here.

2.5. Install MTJ Plugin

MTJ (Mobile Tools for Java™) is a plugin for Eclipse that provides features for developing Java ME applications.

However, it has been archived due to “lack of development activity” and is no longer available in the Eclipse Marketplace.

Notes

If you are experimenting with J2ME SDK 8.3, note that the official Oracle Java ME SDK 8.3 Eclipse Plugins requires MTJ as its dependency (which should be originally automatically fetched from the Eclipse Marketplace), so you need to install MTJ first, or you will meet “dependency not found” errors.

Nowadays, you can only download the whole MTJ project archive here, around 2 GB.

After downloading, extract the archive and get the zip archive at downloads/downloads/drops/<version>/org.eclipse.mtj.update-site-<version>.zip. Choose the latest version (i.e. 2.0.1) and install it in Eclipse by Help -> Install New Software -> Add -> Archive -> select the zip archive. Restart Eclipse after installation.

2.6. Configure the Plugin with SDK

After installing the plugin, you need to configure it before you can start developing. Go to Window -> Preferences -> Java ME, set WTK Root to the directory where you installed the JWT.

Then turn to Device Management, if you see some devices under a group named Sun Java Wireless Toolkit, you are good to go. If not, you need to add WTK devices manually by clicking Manual Install and selecting the root directory of the WTK to scan for devices.

Explanation of “Device” in Java ME

In Java ME, a “device” is a set of profiles which define the language and API capabilities of a target, where the SDK libraries and tools used to build an application is located, and how the application is run and debugged in an emulator (or a real device). Generally speaking, a device defines everything the build system needs to know about the target platform.

There may be some devices named “SDK Provider Test Clamp”. Do NOT use them, as they are dummy devices for testing the SDK itself.

2.7. Create a New Project

Now you can create a new project! Start by selecting File -> New -> Java ME Project. You can choose a project name, the MIDP version, and the CLDC version.

Note that you need to select a WTK device you added in the previous step, NOT the SDK Provider Test Clamp. In my case, I chose DefaultColorPhone, which seems to be a common device for J2ME development.

2.8. Write Your Code

You can now write your code in the src folder. The structure of a J2ME project is similar to an average Java project, with a src folder for source code and a res folder for resources.

You need at least a MIDlet class (like Activity in Android) for a GUI application. I will not go into details about J2ME programming here, and you can find some good tutorials here.

2.9. Run Your Application

If you are on a 32-bit system, you can run your application directly in the emulator by right-clicking the project and selecting Run As -> Emulated Java ME MIDlet. But on 64-bit, you might meet the following error:

java.lang.UnsatisfiedLinkError: C:\WTK2.5.2_01\bin\sublime.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform
	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
	at java.lang.Runtime.load0(Runtime.java:809)
	at java.lang.System.load(System.java:1086)
	at com.sun.kvem.Sublime.<init>(Sublime.java:29)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at java.lang.Class.newInstance(Class.java:442)
	at com.sun.kvem.Lime.createLime(Lime.java:40)
	at com.sun.kvem.KVMBridge.<init>(KVMBridge.java:46)
	at com.sun.kvem.KVMBridge.getBridge(KVMBridge.java:37)
	at com.sun.kvem.midp.MIDP.run(MIDP.java:699)
	at com.sun.kvem.environment.EmulatorInvoker.runEmulatorImpl(EmulatorInvoker.java:107)
	at com.sun.kvem.environment.EmulatorInvoker.main(EmulatorInvoker.java:135)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.sun.kvem.environment.JVM.main(JVM.java:103)

I haven’t found a solution for this yet, but you can build the project to a .jar file and run it on a real device or an emulator like KEmulator or J2me Loader on Android. Just click Application Descriptor in the project and select Create Package to build the .jar file under the deploy folder.

3. Conclusion

That’s it! You have successfully built a Java ME application in 2024. Although Java ME is no longer popular, it’s still a fun (cough) way to learn old Java programming.

If you have any questions or suggestions, feel free to leave a comment.


  1. Though in some countries (like China), many “contract phones” (phones that are given to you for free when you sign a contract with a carrier) continued to provide BREW downloading services and Chinese game developers continued to develop casual games for it until 2020s. I remember myself still playing a carrier-supplied version of NS-Shaft on a ZTE-C R580 around 2019. (Edit: Later I found that the platform may be actually MRP instead of BREW, an application format running in SKYEngine developed by Hangzhou Sky Moblie Co., Ltd.. The time has been too long, and my memory has become blurred.)
  2. https://stackoverflow.com/questions/35430661/java-me-version-history
  3. https://exaud.com/blog/the-history-of-mobile-video-games-part-iii
w568w
梦想改变自己的疯子。