MIDlet ClassLoader

MicroEmulator is using special ClassLoader to load MIDlet midlet classes and resources. This ClassLoader is not used when application is running as applet or --appclassloader system specified.

MIDlet ClassLoader has following functionality

  • bytecode preprocessing/instrumentation
  • Security aware - enables load and run app in Webstart.
  • Enforce class loading order. MIDlet classes loaded first then system (java.) and MicroEmulator classes (javax.)
  • Enforce resource loading order.
  • Enforce static initializers in MIDlet. Each time you start MIDlet new ClassLoader is created.

    ClassLoader configuration

  • --appclasspath | -appcp CLASSPATH » for MIDlet application components if any; ignored when opening .jad
  • --appclass library.class.name » for appclasspath auto detection from system classpath; ignored when opening .jad
  • --appclassloader strict » Default configuration
  • --appclassloader relaxed » Automatically add missing classes to appclasspath by finding them in system classpath
  • --appclassloader delegating » Allow MIDlet to load any classes or resources not found in appclasspath from parent class loader.
  • --appclassloader system » Disable use of MIDlet ClassLoader and use only System class loader. May be usefull for debug.

    MIDlet ClassLoader allow MIDlet to load classes only from MIDlet jar or --appclasspath. Classes from java. and javax.microedition. are loaded from parent class loader e.g. ClassLoader of MicroEmulator application.

    Argument --appclass is a helper for --appclasspath. If your MIDlet application classes are already in system classpath when starting MicroEmulator then --appclass will find the location URL of this class (directory or jar) and add this URL to MIDletClassLoader then same as --appclasspath.

    When MicroEmulator started with MIDlet class (as opposite to jad name) then 'relaxed' classloader used by default.

    MicroEmulator usage

        java -cp CLASSPATH org.microemu.app.Main application.main.MIDlet

    Is effectively the same as

        java -cp CLASSPATH org.microemu.app.Main --appclass application.main.MIDlet application.main.MIDlet
        java -cp CLASSPATH org.microemu.app.Main --appclassloader relaxed application.main.MIDlet

Bytecode preprocessing

We are using ASM for Bytecode manipulations.

At runtime:

  • Calls to System.out, System.err are redirected to Injected.class to enable Logging in MicroEmulator console.
  • Calls to System.getProperty(), are redirected to Injected.class to enable java system properties change in WebStart application.
  • class.getResourceAsStream are redirected to solve resource loading patterns commonly used in MIDlets and not acceptable in Java SE application when System class is called to load MIDlet resource
  • Timers and Threads created by MIDlet are controlled by MicroEmulator and are terminated when MIDlet ends. MIDletTimer and MIDletThread would be used in your application.

"Save for Web...":

We are adding new class org.microemu.Injected to new JAR. Calls to System.getProperty(), System.out, System.err and getResourceAsStream are redirected to MicroEmulator Injected class.