一、选用sun的phoneme https://phoneme.dev.java.net/
二、下载
http://download.java.net/mobileembedded/phoneme/advanced/phoneme_advanced-mr2-dev-src-b97-20_nov_2008.zip
三、解压
unzip phoneme_advanced-mr2-dev-src-b97-20_nov_2008.zip
相关推荐文章《mini2440 移植 Java虚拟机的错误处理 》 http://www.linuxidc.com/Linux/2011-08/41914.htm
四、修改makefile
cd phoneme_advanced_mr2/cdc/build/linux-arm-generic
gedit GNUmakefile
修改 CVM_TARGET_TOOLS_PREFIX=/usr/local/arm/4.3.2/bin/arm-linux- 为自己的交叉编译器的地址
修改 USE_AAPCS ?= false 为 true
五、输出PATH
export PATH=/usr/local/arm/4.3.2/bin/:$PATH 为自己的交叉编译器的地址
六、编译
make
七、如果是使用Ubuntu的朋友,可能要安装sun-java6-jdk和另外的一两个工具
Ubuntu下Java SDK安装配置具体参考见这篇 http://www.linuxidc.com/Linux/2011-08/41913.htm
另外的一两个工具可以通过 apt-get install 来安装(出错时会提醒的)
八、出错
../../src/linux-arm/javavm/runtime/segvhandler_arch.c:45:26: error: asm/ucontext.h: No such file or directory
../../src/linux-arm/javavm/runtime/segvhandler_arch.c: In function 'handleSegv':
../../src/linux-arm/javavm/runtime/segvhandler_arch.c:224: error: dereferencing pointer to incomplete type
../../src/linux-arm/javavm/runtime/segvhandler_arch.c:285: error: dereferencing pointer to incomplete type
../../src/linux-arm/javavm/runtime/segvhandler_arch.c:285: error: dereferencing pointer to incomplete type
../../src/linux-arm/javavm/runtime/segvhandler_arch.c:286: error: dereferencing pointer to incomplete type
../../src/linux-arm/javavm/runtime/segvhandler_arch.c:294: error: dereferencing pointer to incomplete type
修改 segvhandler_arch.c 文件
gedit ../../src/linux-arm/javavm/runtime/segvhandler_arch.c
修改
#define ucontext asm_ucontext
#include
为
//#define ucontext asm_ucontext //注释掉这句
#include //去掉arm/
九、编译
make
编译成功!
ls
可以看到在当前目录有
bin lib testclasses.zip
十、测试
1)、拷贝上面三个文件与文件夹到开发板/home/j2me目录
2)、在开发板/etc/init.d/rcS文件里加入如下
Java_HOME=/home/j2me
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib
3)、经典的HelloWorld
cd /home/j2me/bin
./cvm -cp ../testclasses HelloWorld
可以看到输出了 HelloWorld.
4)、来个全面测试
./cvm -cp ../testclasses.zip Test
*Number of command line arguments: 0
Starting test1
...recurse
...recurse
...recurse
...link
...link
...link
Starting test1 again
...recurse
...recurse
...recurse
...link
...link
...link
test6: Caught inner java.lang.NullPointerException
test6: Caught outer java.lang.NullPointerException
Testing Array Copy
*TestE exception thrown because "I'm feeling Testy"
* threw java.lang.ExceptionInInitializerError
* threw java.lang.NoClassDefFoundError: StaticE
c1 = class [LTest;
c2 = class [[LTest;
c3 = class [LC;
c4 = class [[LC;
c1.modifiers = 1041
c2.modifiers = 1041
c3.modifiers = 1040
c4.modifiers = 1040
*FloatMIN =1.4E-45
*FloatMAX =3.4028235E38
FloatMIN (the int bits) =1
FloatMAX (the int bits) =2139095039
java.lang.IllegalArgumentException: too many dimensions
at java.lang.reflect.Array.multiNewArray(Native Method)
at java.lang.reflect.Array.newInstance(Unknown Source)
at Test.testDeepArrayConstruction(Unknown Source)
at Test.main(Unknown Source)
at sun.misc.CVM.runMain(Unknown Source)
Constructed an object of type
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[LTest;
finally!
Requesting GC with a latency request of 2 seconds
(Turning GC tracing on)
Sleeping 5 seconds, and waiting for GC's
Woke up! Cancelling latency request
.............
*CONGRATULATIONS: test Test completed with 411 tests passed and 0 failures
*Output lines starting with a * should be checked for correctness
*They can be compared to src/share/javavm/test/TestExpectedResult
*CONGRATULATIONS: test Test completed with 411 tests passed and 0 failures
这句话意味着什么,我就不说了~~ 恭喜你!