What Goes Into a JAD?

If you are going to deploy a MIDlet, then you will need a Java Application Descriptor (JAD). It's just a plain text file and you can edit the contents using something as common as Windows Notepad. The Wireless Toolkit will automatically generate JAD files for you but you will still have to tweak them by hand. Not surprisingly this means JAD/JAR mismatches are probably the most frequent culprit behind download errors. Once you get past just "getting it right" you will find all kinds of interesting things in JAD files.

MIDlets are distributed in two parts. Presumably your phone can verify the application is "suitable" by quickly checking the JAD file before downloading the much large JAR file.

The reality is that JAR files aren't all that big and Sprint's Vision network is fast enough that you can download most JARs pretty quickly. Furthermore, I can't say that I've ever initiated a download and seen a phone report that the application isn't suitable. I suppose it's possible if the phone was low on memory or if you tried to put a MIDP 2.0 application on a MIDP 1.0 phone. I've just never seen it.

Usually the phone downloads everything and you don't get an error until something in the JAD doesn't match something about the JAR. At this point you'd rather not hear about the error. Who cares about a mismatch at that point? Personally, I think it's a waste to verify the actual JAR size matches the stated size in the JAD. Likewise, I don't care if the version or vendor name changed. All of these things cause problems while you are trying to develop applications yet they don't provide much value to the end user. However, it's the system that we have to live with, so let's move on.

JAD Example

Let's take a look at the fields you may find in a Sprint PCS JAD file. Here's kind of a complicated example:

MIDlet-1: SendNote, /SendNote.png, SendNote
MIDlet-Data-Size: 1000
MIDlet-Delete-Confirm: Are you sure you want to delete SendNote?
MIDlet-Description: Send text notifications to SprintPCS phones.
MIDlet-Icon: /SendNote.png
MIDlet-Info-URL: http://www.apgap.com/
MIDlet-Install-Notify: http://www.apgap.com/installnotify.php?application=SendNote&version=2.0....
MIDlet-Jar-Size: 23742
MIDlet-Jar-URL: http://www.apgap.com/applications/SendNote.jar?v=2_0_2
MIDlet-Name: SendNote
MIDlet-Vendor: ApGap.com
MIDlet-Version: 2.0.2
SendNote.http-document: composeconfirm
SendNote.http-path: /textmessaging/
SendNote.http-server: messagings.sprintpcs.com
SendNote.smtp-server: smtp.sprintpcs.com
SendNote.smtp-username: @sprintpcs.com
sprintpcs.extensions: SPRINTPCS-1.0

The order of the attributes in the JAD file is completely arbitrary. The phone won't care which one comes first or last. Feel free to rearrange them.

Not all of those are required, of course. In particular, you might notice that I'm using several attributes that start with "SendNote." as configuration parameters for my MIDlet. Once the program is launched, it can retrieve any item in the JAD. This is a handy trick to help you reconfigure a program without needing to rebuild the JAR.

You might notice the long URL on the MIDlet-Install-Notify property. Install-Notify is a very cool feature of J2ME. After a program is installed on a new phone, the AMS will notify a remote server at the specified URL. In this case you can see that I'm passing back the name and version of the application that was just installed. I have a PHP script running on the server that is designed to receive the data and store it to a database. The information is logged along with the date/time and so on. I use this to keep a running count of how many people have installed my software.

JAD Attributes

These attributes are mandatory:

  • MIDlet-1
  • MIDlet-Name
  • MIDlet-Version
  • MIDlet-Vendor
  • MIDlet-Jar-URL
  • MIDlet-Jar-Size

Those are pretty self explanatory, however, pay attention to the Jar-Size. It must be the actual size of the JAR file in bytes. Don't use commas. Don't use the "disk space" of the JAR. You need the actual file size. You can find that in Windows by choosing "properties" from Explorer's pop up menu after you right click on an icon.

These attributes are optional:

  • MIDlet-Description
  • MIDlet-Icon
  • MIDlet-Info-URL
  • MIDlet-Data-Size
  • MIDlet-Install-Notify
  • MIDlet-Delete-Confirm

Sprint PCS JAD Additions

This attribute is an addition by Sprint:

  • sprintpcs.extensions

The extensions attribute doesn't seem to be required for any particular reason. I assume that at some point in the future there may be SPRINTPCS-2.0 extensions and some handsets might look for the correct declaration. For now there is only one set of extensions so any JAD that has this attribute will have it set to SPRINTPCS-1.0.

Sprint has defined several additional attributes that you may include. Here are some of them:

  • Content-Folder
  • Content-1-Handler
  • Content-Storefront-URL
  • Content-Run-Until
  • Content-Run-Count
  • MicroEdition-Configuration: CLDC-1.0
  • MicroEdition-Profile: MIDP-1.0

I'd say all of these attributes are optional but it seems that the Samsung VI660 actually requires the "Content-Folder" attribute. This bug is particularly annoying since from now on, all JADs will have to include a Content-Folder attribute just in case a VI660 comes along.

I'll provide more detail in another article but here are some highlights.

As you might guess, the Content-Folder defines where the handset will store the downloaded MIDlet. The Content-1-Handler will allow you to declare a MIDlet as a handler for new media types or URI schemes. The Content-Run attributes allow you to put a self-destruct mechanism in your MIDlet. The AMS will automatically deactivate the MIDlet after the specified amount of use or at the given time. The MicroEdition parameters are informative but not really used.

More to Follow

As you can see there is a lot to these simple text files. JAD properties can be used to pass data to MIDlets or control the AMS. They enable installation tracking and Sprint even uses JAD files to create Java plug-ins.

There are too many possiblities to cover in one article. Watch for some future articles to demonstrate these features.