Watch out… to all my Mac J2ME coding homies!

If you want to skip all my stoopid writing and get to the point it’s right down towards the bottom.

If you write J2ME (or JavaME, or JME, or whatever the heck Sun wants to call it these days) code on a Mac OS X system then you’ve probably hit your head where I just did once or twice. See I’m new to Mac, new to OS X, new to mobile development so these things are just coming to me. On the Mac you will find no support for the Antenna library. Instead we have Michael Powers (who I’m about to contact) who has taken the liberty of creating an emulator/SDK for JavaME that works on OS X. Great idea except there’s no equivalent for Antenna. so now you got smarty-pantses like me roll their own support for things like writing JadFiles. I actually took the mpowerplayer Java code for the build logic and tried to clumsily wrap it in an Ant task. What I do is something that feels like the most obvious answer but what it comes down to is a subtle problem. I’ll drop the skinny on ya’ to see if you come to the same conclusion I did. (If you see the problem before I point it out keep your mouth shut so the slow people in back can catch up!)

In Java you got this defacto standard that every app be bundled as a Jar file. (While you can always distribute your class files without jarring them and force a CLASSPATH setting on your user community nobody does this anymore because it’s considered as impolite as passing gas and/or breaking out in laughter at someone’s eulogy.) In the jar file you have this cool thing called a manifest file… typically named in all caps MANIFEST.MF and situated conveniently in your jar. I know I’m boring you Java experts out there but bear with me… this is going somewhere. The manifest is just a text file with name/value pairs where the name and value are separated by colons. Now in JavaME (or J2ME, or JE micro edition, or whatever the fancy name is) you have another requirement, or standard or whatever, to include another cool file call a jad file. A Jad file is a Java Application Descriptor that describes your JME application to the device that loads it. It is just a text file with name/value pairs where the name and value are separated by colons. Java Micro Edition specifies that you include the following name value pairs in your Manifest: MIDlet-Version, MIDlet-Info-URL, MicroEdition-Configuration, MIDlet-Name, MIDlet-1, MIDlet-n… etc. Java Micro Edition specifies that you include the following name value pairs in your Jad file: MIDlet-Version, MIDlet-Info-URL, MicroEdition-Configuration, MIDlet-Name, MIDlet-1, MIDlet-n… etc. Would you look at that! I just copied and pasted a sentence. So what would any hard core Java dude do when he’s forced to copy/paste? No! Not start an inheritance heirarchy! Reuse the first thing in the second situation! My superior Java programming skills told me it would be wise to create the manifest using Ant’s Manifest task and then copy and pass it through another homegrown Ant task to add the final attribute required in your Jad as specified by the Steve McNealy MicroE spec. That would be the MIDlet-Jar-Size attribute which you can only discover by building a Jar file with your Java classes in it. So that’s what I did. Makes sense right?

But wait…
Today I ran across a problem that required I consult with a much more senior (both in age and experience… sorry Joe but you’re older than me) developer to figure out. While it makes logical sense to reuse one file format which is so similar to another that they could pass as twins there’s always the subtle gotcha. Nobody called me at 2am in the morning following the day I decided copying would work to inform me that the Manifest spec says somewhere that a line may not be more than 72 characters in length without breaking to the next line via a fancy continuation sequence! It took the insight and cranium power of my more senior colleague (who immediately saw the problem… I mean in less than 60 seconds… the time it would take to make Ready-Pop) to figure out that my Jad file was following the manifest spec. You see while both the manifest and the Jad specs are soooo doggone similar, there’s that wrinkle in the manifest spec (that probably dates back to somebody’s old Win95 machine or Cobol program limitation) that does not (and should not) exist in the Jad spec. So when I went to include an application level parameter, which by the MIDlet spec is introduced via custom name value pair in your Jad file, that happened to include a little more than 72 characters (it was a server URL) the extra characters were wrapped on another line in both my manifest and my Jad. Since the Jad spec doesn’t say anything about wrapping (it might include a bit about rapping) my application only received part of the parameter and started to do the wop. (The wop was a popular hip-hop dance back in the late 80’s early nineties that I believed followed break-dancing. Who the heck does the wop nowadays? I’ll tell you who! My application does it when you pass it crazy server URLs! I guess nobody told the app that the wop was played out by the time I graduated high school.)

In summary…
I really should start making my point early on in these long winded posts. In summary I learned that you can’t make a Jad out of a manifest no matter how well the manifest’s underwear fit on the Jad. These two things are different even though they are the same. I mean they work different even though the contents are similar. Well, I should say they work the same but the spec is different. Well the spec is pretty much the same but laid out slightly different. I mean they’re kinda the same but in different ways… I mean… aww can it! Just make sure you don’t trip over the 72 character thing in your manifest when you create your Jad.

Sincerely Yours…

How do you write your signature? “Yours Truly”, “With Regards”, “Always and Forever”? I’ve been trying a number of different approaches to write my signature. Before we get too detailed let me remind you that you are reading the weblog of a die-hard software engineer so the terms you are familiar with may take on an entirely different meaning within the following body of text. For you first time visitors, wassup, my name’s Cliff. You’re here because you’re looking for some provocative writing… the likes of which is inspiring and thought provoking enough to distract you from the mundane struggles of your daily life.. leading you to another world of adventure filled with colorful characters and… let’s move on, shall we?

So I’m sitting in front of my Dell complete with an Intel Core Duo processor and a flat screen monitor (ooh, thought provoking…) and I’m mashing keys randomly in a desperate attempt to clear the confirmation dialog from the screens of would be users of the mobile phone application I’m developing. (In short I’m trying to add a digital signature to my Midlet so users don’t have to answer security messages. In layman’s terms: I’m trying to certify my software.) Everything I try ends in failure partly because I’m a bad person, partly because I haven’t a clue what I’m doing, partly because I believe everything could be done so much better on my Macbook pro, and partly because you did something sneaky with my source files while I wasn’t looking. So then I’m all on these websites and forums asking questions looking for answers and examples on what REAL people do when they want to deliver a killer mobile product taking the world by storm without raining confirm dialogs on the user community. Towards the end of what’s supposed to be my Thanksgiving vacation I have an epiphany (or a wild revelation or whatever those crazy A-Ha moments are called). I’ve been going about it all wrong. Everything from the digital signature to the way I dress… it’s all wrong! (Beige sweaters with brown slacks and black socks are just a no-no!) You see, when I grew up signing a java application involved doing something to a jar file that guaranteed that you were the sole provider of the content therein. (That something normally meant adding some sort of message digest or wierd crypto-algo-thingy that couldn’t be fooled with my a million super computers in the current age.) Nowadays the youngsters seem to be all about the Jad file. It’s all Jad file this and Jad file that. What I’m saying is digital signature in the mobile world appear to only apply to Jad files leaving the jar file in it’s original shape. I’m not certain about any of this but it sure feels this way. I have some evidence to backup my findings and theories.

Copied verbatim from my post on the Blackberry forums:

I’ve read some documentation on the Sprint Dev netork that details the steps involved in signing a MIDlet suite and it completely leaves out the use of jarsigner. Another clue that jarsigner is not supposed to be used is found in Sun’s Wireless Tool Kit (WTK). When I used WTK to sign my app and checked the jar with jarsigner -verify the jarsigner reports the jar is unsigned. Yet inspection of the jad file reveals the digital signature attributes from my certificate. Last hint comes from Antenna. If you run then the jar file does not get updated, only the jad. If you run signjar prior to wtksign (as I thought I had to) then the jar file is updated with the signature which changes it’s size. However wtksign does not include any logic for updating the jar size attribute. I actually wrote a patch for including the jarsize update logic in wtksign thinking it was an oversight. Now I’m of the belief tha signing a MIDlet simply means adding the Jar RSA and certificate digital info to the Jad.

My team and I have been at this for a while now. nothing seems to work. If there are any wireless mobile gurus out there who are bored enough over the holidays to surf the web and land on my page please save my life by filling out the answer in the text box below. Typical rules and restrictions apply. Answer should be clear, coherent, unbiased and to the point. Answer may also be accompanied by your banking info (routing and account numbers) so that proper payment for given answer may be deducted… *ahem*… deposited into your account. Thanx in advance for any diamond cracking solutions…

Your Truly,
Emperor of 11 Java communities
Emperor Cliff

Can you hear me now?

Update*I found the Sphinx4 project which looks like something I can start with… If anyone knows where to find the API Javadocs or any other documetation for Apple’s Speech engine drop me a line. I’d love to do a comparison. For one I know the voices sound better than FreeTTS.

I’ve been ’round the web looking for a couple of miracles. One of said miracles would come in the flavor of either a Linux-compatible or platform agnostic (Java) full featured VR/TTS system. (For those of you that ain’t down with the fancy acronyms VR = Voice Recognition, TTS = Text To Speech.) Do you know of such a beast? I’ve found several half solutions many arepricey or geared towards Windows. There’s FreeTTS which covers the TTS side ok but requires you incorporate a third party speech database if you want your app to sound like anything less robotic. There are actually two alternative sources for better sounding speech collections, one of which is secured by a non-commercial use license rendering it useless for me. Meanwhile the other option is somewhat complicated so I prefer not to waste my time.

The other miracle would resemble a working end to end solution for signing a J2ME MIDlet. You see, I have this Verisign certificate and I went through the trouble (and I do mean trouble… signing an app is a black art not meant for the faint of heart…) of importing the certificate into my keystore. I believe that’s step 45 of a 5,893 step process that always feels like you’re almost finished. Now when I use either Ant’s signjar, Antenna’s wtksign, or both I can never get the thing to download over the air (also known as installing OTA). It’s almost like I’m missing something but I don’t know what. I can get the jarsigner command line tool to verify the app has been signed (only after invoking the signjar task). I can also get the signatures added to the jar (only after using wtksign which doesn’t seem to sign the jar). But then I must manually update the size attirbute in the jad file after everything has been signed. Where am I going wrong? Have any of you ever managed to get a signature over your application? If so which species of chicken did you use to work your voodoo? Was there a shrunken head involved? Maybe that’s where I’m going wrong. My head is too big for the spell to be cast properly. If you don’t know, lemme know… y’know?