j2me工具命令行攻略及常见问题解决
[email protected]
版权所有,转载请注明出处
------------------------------------------------
wtk的工具使用eclipseme+eclipse非常方便,但是我们必需熟悉一些常用的命令行操作,以便在开发过程中出现问题时可以排除错误.例如,我今天在用wtk的模拟器通过OAT方式运行程序时,就出现了如下错误:
Warning: Running JAM, Ignoring all other options (but "-Xheapsize", and OTA flags if provided)
正在通过存储根 QwertyDevice 来运行
Running with locale: Chinese_People's Republic of China.936
Running in the identified_third_party security domain
** Error installing suite (39): The JAD matches a version of a suite already installed.
Execution completed.
3653833 bytecodes executed
24 thread switches
1665 classes in the system (including system classes)
19019 dynamic objects allocated (571732 bytes)
1 garbage collections (0 bytes collected)
然后模拟器就退出了,大家注意有一行:
** Error installing suite (39): The JAD matches a version of a suite already installed.
提示相同版本的jad已经安装了,好,那改一个版本吧,修改后运行依然出错:
** Error installing suite (17): The application is an older version of one that is already installed
可见,错误很明显:因为此应用已经安装过了,使用如下命令查看安装了哪些应用:
D:\WTK2.5.1\apps\test>emulator -Xjam:list
正在通过存储根 DefaultColorPhone 来运行
Running with locale: Chinese_People's Republic of China.936
Running in the identified_third_party security domain
[1]
Name: myjm Midlet Suite
Vendor: Midlet Suite Vendor
Version: 2.0.0
Storage name: #Midlet%0020#Suite%0020#Vendor_myjm%0020#Midlet%0020#Suite_
Size: 8K
Installed From: http://localhost:8080/ota/myjm/j2me.jad
MIDlets:
HelloWorldPlusMIDlet
MyTestMIDlet
CalendarTest
[2]
Name: test
Vendor: Unknown
Version: 1.0
Description:this is my test Midlets
Storage name: #Unknown_test_
Size: 6K
Installed From: http://10.17.33.191:1260/test/bin/test.jad
MIDlets:
TinyMIDlet
HelloWorldPlusMIDlet
既然这样,那换一个名称吧,OK了,运行成功!
原因找到了,那我们就可以将原来的程序删除后再安装,命令如下:
D:\WTK2.5.1\apps\test>emulator -Xjam:remove=all
正在通过存储根 DefaultColorPhone 来运行
Running with locale: Chinese_People's Republic of China.936
Running in the identified_third_party security domain
Execution completed.
3693460 bytecodes executed
22 thread switches
1665 classes in the system (including system classes)
19407 dynamic objects allocated (583992 bytes)
1 garbage collections (0 bytes collected)
也可以用安装的序号删除指定的程序,如:
D:\WTK2.5.1\apps\test>emulator -Xjam:remove=1
其实,删除还可以直接在模拟器上完成,运行下 emulator -Xjam 看看就知道了.
实际上我们如果只是测试下程序,可使用这个参数,在运行后程序将会自动删除:
emulator -Xjam:transient=http://localhost:8080/ota/myjm/j2me.jad
另外,提醒大家一下,通过OAT下载的时候一定要将httpserver的MIME类型设置正确,不然模拟器会提示MIME类型不正确,正确的MIMI类型应该如下:
<mime-mapping>
<extension>jad</extension>
<mime-type>text/vnd.sun.j2me.app-descriptor</mime-type>
</mime-mapping>
<mime-mapping>
<extension>jar</extension>
<mime-type>application/java-archive</mime-type>
</mime-mapping>
在运行程序时,无论是直接运行JAD,还是OAT方式,都需要将midp和midlet的版本设置正确,查看模拟器支持的版本命令如下:
D:\WTK2.5.1\apps\test>emulator -version
Sun Java(TM) Wireless Toolkit 2.5.1 for CLDC
Profile: MIDP-2.1
Configuration: CLDC-1.1
Optional: J2ME-WS-1.0,J2ME-XMLRPC-1.0,JSR179-1.0.1,JSR180-1.0.1,JSR184-1.1,JSR211-1.0,JSR226-1.0,JSR229-1.1.0,JSR234-1.0
,JSR238-1.0,JSR239-1.0,JSR75-1.0,JSR82-1.1,MMAPI-1.1,SATSA-APDU-1.0,SATSA-CRYPTO-1.0,SATSA-JCRMI-1.0,SATSA-PKI-1.0,WMA-1
.1,WMA-2.0
以上命令主要针对sun的WTK,对于其它厂商的SDK,命令格式应该类似.
=============================================================
下面着重对NOKIA的s60sdk3的常见问题进行一下讨论.
在eclipseme中使用s60的sdk作为模拟器运行OAT方式时,会提示:
Failed to resolve application name
Caught exception:
java.lang.IllegalStateException:No application specified in Jad or command line
...
可见,s60的sdk是不支持OAT方式运行的.即s60的emulator不支持-Xjam参数(参见安装目录的S60_SDK_User_Guide_v3.0a.pdf),只支持-Xdescriptor:<jad file name>
-------------------------------------------
通过jad的方式运行吧,在eclipse提示:
java.io.FileNotFoundException
...
原来是sdk不支持这个格式的文件参数:file:\E:\,在eclispe的run配置中将"file:"去掉后可运行成功,同样在命令行下也可运行成功:
emulator -Xdescriptor:E:\sylilzy\silyWork\eclipse32workspace\myjm\deployed\j2me.jad
(注意:此方式运行时有可能会出现以下错误:
Failed to launch the emulator:
Caught exception:
java.lang.RuntimeException:command failed with Symbian error code:-10508
at com.symbian.tools.j2me.sei.emulator...
...
),将jad的MIDP版本修改为模拟器支持的版本(emulator -version查看)可解决该问题.
然后直接以class的方式运行jar中的类,在eclipse中提示:
Jar file could not be initialized
Caught exception:
java.til.zip.ZipException:invalid entry compressed size(expected 993 but got 996 bytes)
...
用以下命令行出现同样的错误:
E:\sylilzy\silyWork\mgs>emulator -classpath E:\sylilzy\silyWork\eclipse32workspace\myjm\deployed\myjm.jar com.sily.s60.HelloWorldPlusMIDlet
可见eclipse的classs运行应该就是采用上述命令行
分析原因,可能是因为eclipse所打的jar包,在sdk中无法被解压导致,但是为什么采用jad方式运行时可以正确读取jar包中的类呢,无可得知...
但是,在eclipse中create package后,再create obfuscated package后,再通过命令行运行:
emulator -classpath E:\sylilzy\silyWork\eclipse32workspace\myjm\deployed\myjm.jar com.sily.s60.HelloWorldPlusMIDlet
则是OK的,是因为proguard3.9对原myjm.jar包作了修改,反而可以正常运行了 : )
--------------------------------------------------
那现在直接运行class目录中的class会怎样呢,如下:
E:\sylilzy\silyWork\mgs>emulator -classpath E:\sylilzy\silyWork\eclipse32workspace\myjm\bin com.sily.s60.HelloWorldPlusMIDlet
java.lang.Error: ClassFormatError: Inconsistent or missing stackmap at target
- java.lang.Class.invoke_verify(), bci=0
- java.lang.Class.initialize(), bci=117
- java.lang.Class.forName(), bci=0
- com.symbian.midp.runtime.MIDletExecutor$MIDletConstructorThread.run(), bci=43
Uncaught exception: java.lang.RuntimeException: java.lang.Error: ClassFormatError: Inconsistent or missing stackmap at t
arget
- com.symbian.midp.runtime.MIDletExecutor$MIDletConstructorThread.run(), bci=183
-VM verbose connection exited
提示ClassFormatError,这是由于编译的class没有preverify导致的,换SUN WTK编译试试,一样.但是,运行另外一个程序却可以通过:
emulator -classpath E:\sylilzy\silyWork\eclipse32workspace\myjm\bin com.sily.j2me.MyTestMIDlet
the program is running...
-VM verbose connection exited
其实这说明有些类在preverify的时候并没有改变
---------------------------------------
另外,对于s60的模拟器,启动后可不关闭,因为在模拟器上有一个叫做"DebugAgent"的程序专门是用来调试的,这样可在调试时节约启动模拟器的时间.
------------------------------------------------------
综上所述,可见nokia的sdk在与eclipseme的兼容上还存在一些问题,也就是说在 eclipse3.2+eclipseme1.7+nS60_jme_sdk_3rd_e的环境下,想在eclipse下正常运行midlet程序是不可能的,需要手工修改一些配置,或者通过命令行的方式才可将程序正确地运行起来.