Wiki

Clone wiki

javarosa / WebDemos

Web Demos

The purpose of this document is to provide instructions for taking a J2ME jar file and prepare a web emulator demo. This is accomplished using the MicroEmulator package to adapt all of the j2me-specific callout code to mocked j2se callout code.

MicroEmulator

MicroEmulator is a fully J2SE library that can be used to run j2me code with mocked interfaces. Microemu has a few quality use cases in addition to producing these demos, most notably providing a debugging environment that can be used by real profilers.

[http://www.microemu.org/# : MicroEmu Homepage]

Download the platform and unzip the files somewhere to your hard drive

Preparing a Jar

Before you can throw a jar file online to be used with MicroEmu's web applet, it will be necessary to process the Jar file first to wipe out the aforementioned j2me callouts. There are two ways to accomplish this. One is to use the MicroEmu GUI. The other is to use the super sketchy Java Batch Scripting process that I hacked together. Unless you're going to be scripting the creation of these demos, the former is obviously recommended.

Using the Gui

Fire up the MicroEmu by finding the location where you unzipped the package and running microemulator.jar in its root. Go to the File->Open Jar File menu option and locate the appropriate jar archive. Then use File->Save for Web, and provide a location and name for your demo. This will produce a new Jar file, along with a copy of the microemulator java archive and a default html file that looks something like

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
	<head>
		<title>MicroEmulator</title>
	</head>
	<body>
		<applet code="org.microemu.applet.Main"
				width="400" height="600"
				archive="microemu-javase-applet.jar,JavaRosaDemo.jar">
			<param name="midlet" value="org.javarosa.demo.midlet.JavaRosaDemoMidlet">
		</applet>
	</body>
</html>

Some of the common things to need to change before this file is useful are the height and width of the applet (Occasionally it gets cut off on some browsers), and the skin for the emulator you want to use (small, medium, large, etc). Keep in mind that the width and height here are simply applet dimensions, and won't change the size of the actual emulator.

To use a different skin, append the code for the device parameter beneath the midlet paramater.

  <param name="device" value="relative/path/to/skin">

The value of this parameter will be the relative path to the skin folder's device.xml file. For instance, using the build in microemulator Large skin would take the incantation org/microemu/device/large/device.xml

Once you've got the emulator running in a browser, it helps to throw the applet somewhere with a real web-site around it in order to brand it to look less shoddy. I haven't figured out quite yet how to properly throw an applet into the dynamic page content of the www.dimagi.com website, so I've simply been taking the generated source code for a page and dumping that mockup onto a different server after replacing the content with a link to the applet.

[http://build.dimagi.com/pregdemo/webdemo.html : Mocked up Final Web Demo]

Hacking it up

If you need to be able to process Jar files in a more automated fashion, you'll need to use my hacked up jar scripting system. MicroEmu doesn't provide an API for accessing the web demo prep code, so I compiled a class file which can access it At some point, there should be a better solution for this, but don't waste too much time making it more reasonable unless there's good cause.

This scripting system is currently running live on 192.168.7.207, the windows ex-build-server, if you need something to start off of.

First, find and javac the PrepareMidlet.java file attached to this page, or just take the PrepareMidlet.class file. Also nab the preparejar.bat file that's attached.

You'll need to create your own html file to contain the applet, so grab the one that is outlined earlier in this file and create a place for it. You'll also need the microemulator.jar file in the same directory.

Now you should have the following things all in one directory.

  • PrepareMidlet.class
  • somehtmlfile.html
  • YourJar.jar
  • preparejar.bat

You can use the preparejar.bat file to automate creating a Jar file, but first you'll need to open it in an editor and replace the path references. The current file looks like

java -cp C:\javarosa\livedemo\microemulator.jar;C:\javarosa\livedemo\ PrepareMidlet file:\\\C:\javarosa\livedemo\JavaRosaDemo.jar JavaRosaLive.jar

Once you've replaced all of the paths with the path of the directory where all of the files live, and replaced JavaRosaDemo and JavaRosaLive with the names of your source and target Jars, you should be ready to roll.

Updated