先安装netbeans的 j2me开发插件
之后添加 "JAVA平台管理" -> J2ME -> 定制J2ME平台 仿真器 (翻译过来就这个含义) 之后添加 BB模拟器的路径
然后填写一些基本信息(略过)
下一步之后,移除除开net_rim_api.jar的所有jar包(只保留net_rim_api.jar一个)
然后新建J2ME项目
修改默认的build.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- You may freely edit this file. See commented blocks below for --> <!-- some examples of how to customize the build. --> <!-- (If you delete it and reopen the project it will be recreated.) --> <project name="BlackberryZWhereCallMe" default="jar" basedir="."> <description>Builds, tests, and runs the project .</description> <import file="nbproject/build-impl.xml"/> <!-- 定义任务语法 --> <typedef resource="bb-ant-defs.xml" classpath="E:\bb-ant-tools.jar" /> <property name="rim.blackberry.home" location="C:/Program Files/Research In Motion/BlackBerry JDE 4.5.0"/> <property name="rim.blackberry.emulator" value="8700-black"/> <property name="rim.blackberry.jdwp.port" value="8001"/> <!-- cod文件生成目录 --> <property name="dist" value="E:\codeproject\BlackberryZWhereCallMe\dist\snk"/> <target name="bbbuild" description="blackberry build" depends="init"> <mkdir dir="${dist}" /> <rapc quiet="false" output="${name}" jdehome="${rim.blackberry.home}" destdir="${dist}" srcdir="E:\codeproject\BlackberryZWhereCallMe\src"> <jdp title="zWhereCallMe" vendor="zhangjianying" version="0.1" description="Is CopyRight by zjy" systemmodule="true" runonstartup="true" startuptier="7" type="library" /> </rapc> </target> <target name="post-jar"> <antcall target="bbbuild" /> <!-- <exec os="Windows NT Windows 95 Windows 98 Windows 2000 Windows XP" dir="${dist.root.dir}" executable="${rim.blackberry.home}/bin/rapc.exe" failοnerrοr="true" resolveExecutable="true"> <arg value="import=${rim.blackberry.home}/lib/net_rim_api.jar"/> <arg value="codename=${name}"/> <arg value="-midlet"/> <arg value="library=BlackberryZWhereCallMe"/> <arg value="BlackberryZWhereCallMe.rapc warnkey=0x52424200;0x52525400"/> <arg value="jad=${dist.jad}"/> <arg value="${dist.jar}"/> </exec> --> <!-- <echo description="">${jde.home}/lib/net_rim_api.jar</echo> <rapc output="BlackberryZWhereCallMe" jdkhome="E:/资料/JDK_IBM" quiet="false" srcdir="E:/codeproject/BlackberryZWhereCallMe/src" import="${jde.home}/lib/net_rim_api.jar" jdehome="${jde.home}" > <jdp title="Kick Ass App" vendor="Slashdev" version="1.0" type="library" /> </rapc> --> <!-- <copy file="${name}.alx" todir="${dist.root.dir}"/> --> </target> <target name="run" depends="init,jar"> <echo message="dddd=== ${dist.root.dir}"/> <copy todir="${rim.blackberry.home}/simulator" verbose="true"> <fileset dir="${dist.root.dir}\snk"> <include name="**/${name}.*"/> </fileset> </copy> <exec os="Windows NT Windows 95 Windows 98 Windows 2000 Windows XP" dir="${rim.blackberry.home}/simulator" executable="${rim.blackberry.home}/simulator/${rim.blackberry.emulator}.bat" failοnerrοr="true" resolveExecutable="true"/> </target> <target name="debug" depends="init,jar"> <copy todir="${rim.blackberry.home}/simulator" verbose="true"> <fileset dir="${dist.root.dir}"> <include name="**/${name}.*"/> </fileset> </copy> <delete file="${preprocessed.dir}/.timestamp"/> <parallel> <property name="jpda.port" value="${rim.blackberry.jdwp.port}"/> <java jar="${rim.blackberry.home}/bin/JDWP.jar" fork="true" dir="${rim.blackberry.home}/bin"> <jvmarg value="-Xmx256M"/> </java> <sequential> <sleep seconds="5"/> <antcall target="nbdebug"/> </sequential> </parallel> </target> <target name="init.rim.blackberry" depends="init"> <condition property="rim.blackberry" value="true"> <or> <equals arg1="Test" arg2="${config.active}"/> </or> </condition> </target> <target name="post-clean"> <echo>Post clean</echo> <delete> <fileset dir="${rim.blackberry.home}/simulator"> <include name="**/${name}.*"/> </fileset> </delete> </target> </project>
注意事项 :
1 如果编译过程中出现 不能创建JVM的提示
到netbeans/etc目录下修改相应的netbeans的启动参数(如果你做了优化就容易引起这个问题)
另一个办法就是下载bb-ant-tools.jar的源码,修改一段代码:
将 ca.slashdev.bb.tasks.RapcTask
中的executeRapc()方法下的
List<String> jvmArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();
for (String arg : jvmArgs) {
if (arg.startsWith("-X"))
java.createJvmarg().setValue(arg);
}
这段代码注释掉.
2 出现不支持的字符集警告时,
在netbeans中点工程的属性,将工程的字符集设置成警告中提醒的(如GBK)
3 不要使用默认dist文件目录作为输出目录,展不清楚为什么,使用默认默认目录的时候,会将源码一起编译到cod文件中 (查看方法用记事本直接打开编译后的cod会发现源码也打进去了)
因此可以在 dist后加一个子目录,比如 snk ,或者 4.5 ,5.0 等