当前页面: 开发资料首页 → Netbeans 专题 → J2ME MIDP Device Fragmentation Tutorial with Marv The Miner(2)
摘要: This tutorial shows how to configure the IDE to work with existing Java? 2, Micro Edition Platform (J2ME? Platform) MIDP projects and, specifically, how to use the NetBeans? IDE's built-in solution to the device fragmentation problem.
At this point, we should be able to compile and run the program for all of our configurations. Clicking any of the icons in the main toolbar will execute the selected action for the Active configuration.
If you did not have access to one or more of the emulator platforms containing the correct APIs, this step might fail. If that is the case, you should manually comment out any line making a call to an API that you don't have.
Preverification will fail for the Motorola configuration if you have not followed the steps to manually install the motoral emulator described in the section for non-UEI emulators. To make this configuration compile without manually adding the emulator, you can comment out all motorola API calls and remove the motorola libs from the Libraries & Resources panel.
This tutorial should have given you a good understanding of how you can import your existing MIDP projects into the NetBeans environment, but it does not cover all of the Device Fragmentation issues solved by the IDE. Below are some more examples of common problems and how they can be solved within the IDE.
If, for example, you have two projects MyLibrary and MyApplication, both containing two configurations ReleaseConfiguration and DebugConfiguration, then you would take the following steps to set up the dependency correctly:
This is the manner in which you should set up dependencies between projects when configurations are involved.
large_res.Jar
, medium_res.Jar
, small_res.Jar
each
containing resources of the same name, but different resolutions.
Then point your Nokia_large, Nokia_med, Nokia_small
configurations at the correct version. Though only 3rd party emulator platforms that follow the UEI specification can be automatically detected by the IDE, non-UEI complient emulators can still be used. This section describes how it can be done.
<?xml version='1.0'?> <!DOCTYPE platform PUBLIC '-//NetBeans//DTD J2ME PlatformDefinition 1.0//EN' 'http://www.netbeans.org/dtds/j2me-platformdefinition-1_0.dtd'> <platform name="Motorola_7_5" home="C:\WTK\Motorola\SDK v4.1 for J2ME\Emulator7.5" type="custom" displayname="Motorola 7.5" srcpath="" preverifycmd=""{platformhome}/bin/preverify.exe" -classpath "{classpath}" -d "{destdir}" "{srcdir}"" runcmd=""> <device name="Motorola_7_5" securitydomains="trusted,untrusted" description="Motorola_7_5"> <configuration name="CLDC" version="1.1" displayname="CLDC" classpath="${platform.home}/lib/cldc.zip" dependencies="" default="true"/> <profile name="MIDP" version="2.0" displayname="MIDP" classpath=";${platform.home}/lib/midp.zip" dependencies="" default="true"/> </device> </platform>
You will need to restart the IDE after saving this XML file. Once you have done so, you will be able to choose Motorola 7 5 as a platform and Motorola_7_5 as a device. You should associate the Motorola configuration with this new platform. Note that you may need to delete the cache files located in {userhome}\var\cache in order for the manually installed platform to be detected. Also, you should not delete the mdrstorage folder that may also be located there.
Notice that the runcmd attribute is set to empty string. This is because the command to start this Motorola emulator takes the MIDlet to execute as one of its parameters. This is nothing like UEI standards, and cannot be directly supported in the IDE. However...
If your emulator requires additional information (such as the location of project Jar or the name of the MIDlet to execute), you can execute emulators by modifying the build.xml file located in your project home directory.
This file controls all project actions. We can create a new target here that executes the motorola emulator and passes all appropriate data whenever the Run action is invoked on the Motorola configuration.
Add the following code your project's build.xml:
<target description="Run MIDlet suite." depends="init" name="run"> <condition property="run.motorola"> <!-- arg2 must match the configuration name you would like to use the special emulator --> <equals arg1="${config.active}" arg2="Motorola"/> </condition> <ant inheritrefs="true" inheritall="true" target="run_normal"/> <ant inheritrefs="true" inheritall="true" target="run_motorola"/> </target> <target description="Run MIDlet suite the normal way." depends="init" name="run_normal" unless="run.motorola"> <nb-run commandline="${platform.runcommandline}" securitydomain="${evaluated.run.security.domain}" execmethod="${run.method}" platformtype="${platform.type}" platformhome="${platform.home}" device="${platform.device}" jadurl="${dist.jad.url}" jadfile="${dist.dir}/${dist.jad}"/> </target> <target description="Run MIDlet suite for motorola's non-UEI emulator." depends="init" name="run_motorola" if="run.motorola"> <property name="project.home" location="."/> <!-- the last arg line contains an value "Miner". This must match the name of the midlet you want to execute --> <java dir="${platform.home}/bin" fork="true" classname="com.mot.tools.j2me.emulator.Emulator" classpath="${platform.home}/bin/Emulator.jar;${platform.home}/bin/configtool.jar"> <jvmarg value="-Djava.library.path=${platform.home}/lib"/> <arg value="-classpath${project.home}/${dist.dir}/${dist.jar}"/> <arg line="-deviceFile"/> <arg value="${platform.home}/bin/RESOUR~1/T720I~1.PRO"/> <arg line="javax.microedition.midlet.AppManager Miner -JSA 1 1"/> </java> </target>
So the run_motorola
target will be run whenever
the active configuration is Motorola. Otherwise, the run_normal
target (which uses the normal emulator execution)
will be invoked.
This concludes the Marv the Miner tutorial.