ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

MIDlet Packaging with J2ME
Pages: 1, 2, 3, 4, 5

What follows is a short example to print various attributes from both those files.



manifest.mf is stored as part of showProperties.jar:

MIDlet-Name: Show Properties MIDlet
MIDlet-Version: 1.0.1
MIDlet-Vendor: My Corporation Inc.
MIDlet-1: ShowProps, , showProperties
MicroEdition-Profile: MIDP-1.0
MicroEdition-Configuration: CLDC-1.0
MIDlet-Description: A simple property list example
MIDlet-Data-Size: 1500

Contents of showProperties.jad:

MIDlet-Name: Show Properties MIDlet
MIDlet-Version: 1.0.1
MIDlet-Vendor: My Corporation Inc.
MIDlet-Jar-URL: file://showProperties.jar
MIDlet-Jar-Size: 1132
MIDlet-1: ShowProps, , showProperties
JadFile-Version: 1.5
MIDlet-Data-Size: 500

Contents of showProperties.java:

import javax.microedition.midlet.*;

public class showProperties extends MIDlet
{
public void startApp() throws MIDletStateChangeException
{
System.out.println("Vendor: " + getAppProperty("MIDlet-Vendor"));
System.out.println("Description: " + getAppProperty("MIDlet-Description"));
System.out.println("JadFile Version: " + getAppProperty("JadFile-Version"));
System.out.println("MIDlet-Data-Size: " + getAppProperty("MIDlet-Data-Size"));
}

public void pauseApp()
{ }

public void destroyApp(boolean unconditional)
{ }

}

Screen shot.
Figure 1

Here are a few important points:

  • The file manifest.mf is stored as part of the JAR file showProperties.jar
  • showProperties.jar is referenced from the JAD file showProperties.jad with the line,
    MIDlet-Jar-URL: file://showProperties.jar 
  • When you preview the JAD file, it locates the associated JAR file with the line from above and reads the contents of the manifest file.
  • The attributes MIDlet-Name, MIDlet-Version and MIDlet-Vendor are in both the manifest file in the JAR and the JAD file. All the values are required to be identical.
  • The attribute MIDlet-Description is from the manifest file and is optional.
  • The attribute JadFile Version is not in Table 1 and, thus, is a user-defined attribute. Because attributes inside a JAD file are accessible from a MIDlet, you can add attributes to the JAD without having to change the JAR file. Put another way, you can easily change or add parameters to be passed to the MIDlet.
  • The attribute MIDlet-Data-Size is in both the manifest and the JAD file. As pointed out earlier, when there are identical attributes in both files, entries in the JAD file will take precedence. Thus, output in figure Figure 1 shows MIDlet-Data-Size as 500, the value from the JAD file. Keep in mind that this does not apply to MIDlet-Name, MIDlet-Version, or MIDlet-Vendor, which are required to be in both files and must be identical.

Pages: 1, 2, 3, 4, 5

Next Pagearrow