这是我在Linux下的一个实验,需要搞定7个比较基础的J2ME程序。真不知道我为什么做这么多无聊的事……
首先是操作环境和软件版本:
操作系统: Arch Linux (更新至 20081204)
JDK环境: jdk-1_5_0_17-linux-i586.bin
下在地址: http://Java.sun.com/javase/downloads/index_jdk5.jsp
Eclipse环境: eclipse-java-ganymede-SR1-linux-gtk.tar.gz
下载地址: http://www.eclipse.org/downloads/
J2ME版本: j2me_wireless_toolkit-2_2-linux-i386.bin
j2me_wireless_toolkit-2_2-update_1-linux.zip
下载地址: http://java.sun.com/products/sjwtoolkit/download-2_2.html
EclipseME环境: eclipseme.feature_1.7.9_site.zip
下载地址: http://eclipseme.org/
JDK的安装和配置
# 把jdk安装文件拷在当前用户目录下的 homework/,直接执行安装。
user@~/homework$ sh jdk-1_5_0_17-linux-i586.bin
# 设置jdk环境变量:
user@~/homework$ export JAVA_HOME=/home/kldscs/homework/jdk1.5.0_17
user@~/homework$ export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
user@~/homework$ export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
# 如果要使环境变量在系统重启或用户注销后仍然可用,
# 则可以把刚才执行的命令内容写入用户根目录下 .bashrc文件,
# 或者系统环境变量控制文件 /etc/profile
user@~/homework$ vi ~/.bashrc
user@~/homework$ sudo vi /etc/profile
安装Eclipse
解压Eclipse压缩包:
~/homework$ tar -xvf eclipse-java-ganymede-SR1-linux-gtk.tar.gz
加压后在 ~/homework/eclipse/ 双击eclipse就可以运行,如果需要定义jre环境,在 Window -> Preferences -> Java->Installed JREs->Add 添加你的JRE路径。
这里选择 ~/homework/workspace 作为工作区目录
安装WTK2.2
# 命令行进入存放 j2me_wireless_toolkit-2_2-linux-i386.bin 的目录
user@~/homework$ sh j2me_wireless_toolkit-2_2-linux-i386.bin
Setup has enough information to start copying the program files.
Current Settings:
Destination Directory
/home/user/homework/WTK2.2/
JVM Folder
/home/user/homework/jdk1.5.0_17/bin/
# 如果完成安装,会出现以下的画面
Extracting the installation files…
Documentation for the J2ME Wireless Toolkit version 2.2 is in the file
/home/user/homework/WTK2.2/index.html
In order to start using the J2ME Wireless Toolkit, please run
/home/user/homework/WTK2.2/bin/ktoolbar
# 给WTK打上补丁,解压 j2me_wireless_toolkit-2_2-update_1-linux.zip 至WTK2.2安装目录.
user@~/homework$ cp j2me_wireless_toolkit-2_2-update_1-linux.zip ./WTK2.2/
user@~/homework$ cd WTK2.2/
user@~/homework/WTK2.2$ unzip j2me_wireless_toolkit-2_2-update_1-linux.zip
Archive: j2me_wireless_toolkit-2_2-update_1-linux.zip
replace bin/libzayit.so? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
# 测试一下是否安装成功:
user@~/homework/WTK2.2$ cd ./bin/
user@~/homework/WTK2.2/bin$ ./ktoolbar
WTK OTA server started …
# 安装成功,这里会出现一个GUI窗口
安装EclipseME
# 首先解压 eclipseme.feature_1.7.9_site.zip
user@~/homework$ mkdir eclipseme
user@~/homework$ cp eclipseme.feature_1.7.9_site.zip eclipseme/
user@~/homework$ cd eclipseme/
user@~/homework/eclipseme$ unzip eclipseme.feature_1.7.9_site.zip
启动Eclipse, Help->Software Updates->Available Software->Add Site, 填入 “/home/user/homework/eclipseme”, 选择 “EclipseME” -> Install 。
安装成功重启Eclipse,Help菜单下会有一个 EclipseME 选项。
在Eclipse中配置WTK
启动Eclipse, Window -> Preferences ,进入配置窗口。
选择 J2ME菜单,在 WTK Root 里填入WTK的安装目录
J2ME->Device Management->Import, 目录项填入 /home/user/homework/WTK2.2/bin , 刷新按钮 Refresh ,
确定 Finsh, 然后选择自己比较喜欢的一款手机皮肤。
J2ME->Packaging->Obfuscation, 填入WTK的安装目录 /home/user/homework/WTK2.2 。 搞定!
可以写一个简单的 Hello World程序测试一个:
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class hello extends MIDlet {
Display display;
public hello() {
super();
display = Display.getDisplay(this);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
Form form = new Form(“Another Hello World”);
form.append(“Hello World!”);
display.setCurrent(form);
}
}