https://github.com/ading2210/setup-j2me-sdk
A tutorial on how to set up the J2ME SDK with Intellij on modern Windows or Linux systems.
https://github.com/ading2210/setup-j2me-sdk
Last synced: 3 months ago
JSON representation
A tutorial on how to set up the J2ME SDK with Intellij on modern Windows or Linux systems.
- Host: GitHub
- URL: https://github.com/ading2210/setup-j2me-sdk
- Owner: ading2210
- Created: 2025-02-10T22:18:34.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-02-12T21:32:08.000Z (11 months ago)
- Last Synced: 2025-03-11T23:36:52.074Z (10 months ago)
- Homepage:
- Size: 23.4 KB
- Stars: 3
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# J2ME SDK Tutorial for Intellij
This is a tutorial for setting up the J2ME SDK on modern Windows or Linux distros, using a recent version of IntelliJ. You may find this guide useful if you are particpating in the [Hack Club Retrospect J2ME event](https://retrospect.hackclub.com/j2me).

This is the guide for Linux. For the Windows setup guide, see [`windows_setup.md`](https://github.com/ading2210/setup-j2me-sdk/blob/main/windows_setup.md).
## 1. Set up Directories
Create a directory to put the SDK and related files. I'll use `~/j2me`.
```
~$ mkdir ~/j2me
~$ cd j2me
```
## 2. Download the Sun Java Wireless Toolkit
Download and extract the [Sun Java Wireless Toolkit](https://www.oracle.com/java/technologies/java-archive-downloads-javame-downloads.html) by running these commands. Don't worry, you don't need an Oracle account here.
```
~/j2me$ wget -c --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/sun_java_wireless_toolkit/2.5.2_01/sun_java_wireless_toolkit-2.5.2_01-linuxi486.bin.sh"
--2025-02-10 14:08:23-- https://download.oracle.com/otn-pub/java/sun_java_wireless_toolkit/2.5.2_01/sun_java_wireless_toolkit-2.5.2_01-linuxi486.bin.sh
Resolving download.oracle.com (download.oracle.com)... 23.196.36.113
Connecting to download.oracle.com (download.oracle.com)|23.196.36.113|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/otn-pub/java/sun_java_wireless_toolkit/2.5.2_01/sun_java_wireless_toolkit-2.5.2_01-linuxi486.bin.sh [following]
--2025-02-10 14:08:24-- https://edelivery.oracle.com/otn-pub/java/sun_java_wireless_toolkit/2.5.2_01/sun_java_wireless_toolkit-2.5.2_01-linuxi486.bin.sh
Resolving edelivery.oracle.com (edelivery.oracle.com)... 2600:1406:5400:486::366, 2600:1406:5400:4af::366, 184.28.231.219
Connecting to edelivery.oracle.com (edelivery.oracle.com)|2600:1406:5400:486::366|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://download.oracle.com/otn-pub/java/sun_java_wireless_toolkit/2.5.2_01/sun_java_wireless_toolkit-2.5.2_01-linuxi486.bin.sh?AuthParam=1739225424_622a9caf2f8c1940e97052f7207447da [following]
--2025-02-10 14:08:24-- https://download.oracle.com/otn-pub/java/sun_java_wireless_toolkit/2.5.2_01/sun_java_wireless_toolkit-2.5.2_01-linuxi486.bin.sh?AuthParam=1739225424_622a9caf2f8c1940e97052f7207447da
Connecting to download.oracle.com (download.oracle.com)|23.196.36.113|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 39797585 (38M) [application/x-sh]
Saving to: ‘sun_java_wireless_toolkit-2.5.2_01-linuxi486.bin.sh’
sun_java_wireless_toolkit-2.5.2 100%[====================================================>] 37.95M 23.6MB/s in 1.6s
2025-02-10 14:08:26 (23.6 MB/s) - ‘sun_java_wireless_toolkit-2.5.2_01-linuxi486.bin.sh’ saved [39797585/39797585]
~/j2me$ mkdir sdk
~/j2me$ unzip -q sun_java_wireless_toolkit-2.5.2_01-linuxi486.bin.sh -d sdk/
warning [sun_java_wireless_toolkit-2.5.2_01-linuxi486.bin.sh]: 26624 extra bytes at beginning or within zipfile
(attempting to process anyway)
~/j2me$ rm sun_java_wireless_toolkit-2.5.2_01-linuxi486.bin.sh
```
## 3. Download a 32 Bit JDK
Download and extract the 32 bit Java 8 JDK by running these commands. We're going to use Huawei's mirror to skip logging into an Oracle account.
```
~/j2me$ wget "https://repo.huaweicloud.com/java/jdk/8u202-b08/jdk-8u202-linux-i586.tar.gz"
--2025-02-10 14:10:27-- https://repo.huaweicloud.com/java/jdk/8u202-b08/jdk-8u202-linux-i586.tar.gz
Resolving repo.huaweicloud.com (repo.huaweicloud.com)... 199.91.74.185, 149.104.73.27, 199.91.74.184, ...
Connecting to repo.huaweicloud.com (repo.huaweicloud.com)|199.91.74.185|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 197025433 (188M) [application/octet-stream]
Saving to: ‘jdk-8u202-linux-i586.tar.gz’
jdk-8u202-linux-i586.tar.gz 100%[====================================================>] 187.90M 12.6MB/s in 13s
2025-02-10 14:10:42 (14.0 MB/s) - ‘jdk-8u202-linux-i586.tar.gz’ saved [197025433/197025433]
~/j2me$ tar -xf jdk-8u202-linux-i586.tar.gz
~/j2me$ ls
jdk1.8.0_202 jdk-8u202-linux-i586.tar.gz sdk
~/j2me$ rm jdk-8u202-linux-i586.tar.gz
```
## 4. Install and run IntelliJ IDEA Community Edition 2019.3.
### Using snap
[Make sure that snap's installed](https://snapcraft.io/docs/installing-snapd). On Debian, do `sudo apt install snapd` first.
```
~/j2me$ sudo snap install intellij-idea-community --channel=2019.3/stable --classic
intellij-idea-community (2019.3/stable) 2019.3.5 from jetbrains✓ installed
~/j2me$ snap run intellij-idea-community
```
### Using an unofficial public archive
```
~/j2me$ wget https://github.com/mmk2410/intellij-idea-community/raw/bb2c011025c423d4c971fb19ef8fde6c4027d4bd/intellij-idea-community_2019.3.4-1_all.deb
~/j2me$ sudo apt update && sudo apt install ./intellij-idea-community_2019.3.4-1_all.deb
~/j2me$ intellij-idea-community
```
## 5. Install Intellij Plugins
On the welcome screen, configure your plugins.

You can install the J2ME plugin here.

## 6. Setup Intellij Project
Create a J2ME project and specify the path to the SDK you already downloaded.

Under the `File > Project Structure > SDKs` menu, add the JDK you downloaded earlier.

In the settings for the Sun Wireless Toolkit, make sure it's set to use `1.8` as the JavaSDK.

Under `File > Settings > Build, Execution, Deployment > Compiler > Java Compiler` make sure the project bytecode version is `1.4`.

Add in your `MainMIDlet` class.

In `File > Project Structure > Artifacts`, create a new JAR artifact with the proper module.

Make sure the output directory for your JAR is the same as the project's root directory.

In the top right corner click on "Add Configuration"

In that menu, create a new J2ME run configuration.

Change the run mode to class, then set the proper MIDlet class.

In the before launch options, make it build the project and then the JAR artifact.

## 7. Fix SDK Emulator Script
The original emulator script tries to run the wrong Java version.
The original script is located at `sdk/bin/emulator` and looks like this:
```
~/j2me$ cat sdk/bin/emulator
#!/bin/sh
javapathtowtk=
PRG=$0
# Resolve soft links
while [ -h "$PRG" ]; do
ls=`/bin/ls -ld "$PRG"`
link=`/usr/bin/expr "$ls" : '.*-> \(.*\)$'`
if /usr/bin/expr "$link" : '^/' > /dev/null 2>&1; then
PRG="$link"
else
PRG="`/usr/bin/dirname $PRG`/$link"
fi
done
KVEM_BIN=`dirname "$PRG"`
KVEM_HOME=`cd "${KVEM_BIN}/.." ; pwd`
KVEM_LIB="${KVEM_HOME}/wtklib"
export MMAPI_GM_SOUNDBANK="${KVEM_HOME}/lib/soundbank.dls"
"${javapathtowtk}java" -Dkvem.home="${KVEM_HOME}" \
-Djava.library.path="${KVEM_HOME}/bin" \
-cp "${KVEM_LIB}/kenv.zip:${KVEM_LIB}/ktools.zip:${KVEM_LIB}/customjmf.jar" \
com.sun.kvem.environment.EmulatorWrapper "$@" 0
```
Edit the `javapathtowtk=` line to instead be:
```
javapathtowtk="$(realpath "$(dirname "$0")"/../../jdk1.8*)/bin/"
```
And save the file.
## 8. Install Missing 32 Bit Libraries
If you try running the emulator at this stage, it will fail because it's missing 32 bit shared libraries. Identify the ones you need using `ldd`.
```
~/j2me$ ldd sdk/bin/libzayit.so
linux-gate.so.1 (0xf7efd000)
libXt.so.6 => not found
libX11.so.6 => /lib/i386-linux-gnu/libX11.so.6 (0xf76fd000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xf75f8000)
libnsl.so.1 => /lib/i386-linux-gnu/libnsl.so.1 (0xf75dd000)
libICE.so.6 => /lib/i386-linux-gnu/libICE.so.6 (0xf75c0000)
libSM.so.6 => /lib/i386-linux-gnu/libSM.so.6 (0xf75b5000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xf75b0000)
libstdc++.so.6 => /lib/i386-linux-gnu/libstdc++.so.6 (0xf7390000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xf7369000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf713f000)
libxcb.so.1 => /lib/i386-linux-gnu/libxcb.so.1 (0xf7111000)
/lib/ld-linux.so.2 (0xf7eff000)
libbsd.so.0 => /lib/i386-linux-gnu/libbsd.so.0 (0xf70fa000)
libuuid.so.1 => /lib/i386-linux-gnu/libuuid.so.1 (0xf70f0000)
libXau.so.6 => /lib/i386-linux-gnu/libXau.so.6 (0xf70eb000)
libXdmcp.so.6 => /lib/i386-linux-gnu/libXdmcp.so.6 (0xf70e4000)
libmd.so.0 => /lib/i386-linux-gnu/libmd.so.0 (0xf70d5000)
```
If you're on Ubuntu or Debian, make sure your system is configured to install i386 packages by adding the corresponding package sources:
```
~/j2me$ sudo dpkg --add-architecture i386
~/j2me$ sudo apt update
Hit:1 http://archive.ubuntu.com/ubuntu oracular InRelease
Hit:2 http://archive.ubuntu.com/ubuntu oracular-security InRelease
Get:3 http://archive.ubuntu.com/ubuntu oracular/main i386 Packages [1064 kB]
Get:4 http://archive.ubuntu.com/ubuntu oracular/universe i386 Packages [8526 kB]
Get:5 http://archive.ubuntu.com/ubuntu oracular-security/main i386 Packages [103 kB]
Get:6 http://archive.ubuntu.com/ubuntu oracular-security/universe i386 Packages [49.7 kB]
Fetched 9743 kB in 1s (6932 kB/s)
11 packages can be upgraded. Run 'apt list --upgradable' to see them.
```
If you're on Debian or Ubuntu, you can find which packages include the missing libraries using `apt-file`.
```
~/j2me$ apt-file search libXt.so.6
libxt6: /usr/lib/x86_64-linux-gnu/libXt.so.6
libxt6: /usr/lib/x86_64-linux-gnu/libXt.so.6.0.0
```
Then you can just install those packages. Make sure to specify that they are 32 bit.
```
~/j2me$ sudo apt install libxt6:i386
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
libxt6:i386
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 192 kB of archives.
After this operation, 485 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bookworm/main i386 libxt6 i386 1:1.2.1-1.1 [192 kB]
Fetched 192 kB in 0s (1,498 kB/s)
Selecting previously unselected package libxt6:i386.
(Reading database ... 626617 files and directories currently installed.)
Preparing to unpack .../libxt6_1%3a1.2.1-1.1_i386.deb ...
Unpacking libxt6:i386 (1:1.2.1-1.1) ...
Setting up libxt6:i386 (1:1.2.1-1.1) ...
Processing triggers for libc-bin (2.36-9+deb12u9) ...
```
## 9. Running the Project
Now, you can just hit the run button in IntelliJ to build your project and run it in the emulator.

You can even debug it.
