Running Java Applications on the PocketPC

This book uses PersonalJava 1.2 for developing Java applications on the PocketPC. Since the Jeode JVM[2] is an implementation of PersonalJava 1.2, we must use a Java 1.1 compiler to compile source code for running on the PocketPC. The Ant build target CompilePocketPC compiles the PocketPC source code.

[2] The Jeode JVM is distributed on the application CD accompanying iPaqs and many other PocketPCs. It may not be installed out-of-the-box, but it is simple to install from the CD. Alternatively, Jeode can be purchased from http://www.handango.com.

<target name="CompilePocketPC" depends="CompileDesktop">
  <!-- Compile the PocketPC source code -->
  <javac srcdir="${pocketpcsource}"
    target="1.1"
    bootclasspath="${jdk-base}\lib\classes.zip"
    destdir="${pocketpcdestination}"
    fork="true"
    executable="${jdk-base}\bin\javac"
    compiler="javac1.1">
    <classpath>
      <pathelement location="${desktoplib}\javaonpdas-desktop.jar"/>
      <pathelement location="${pocketpclib}\${pocketpcsoaplib}"/>
    </classpath>
  </javac>
  <jar jarfile="${pocketpcdestination}\pocketpc.jar"
       basedir="${pocketpcdestination}"
       includes="**\*.class"
  />
</target>

This build target compiles the source code with the Java 1.1 compiler, and produces a JAR called pocketpc.jar.

The DeployPocketPC build target copies the pocketpc.jar file to the ${pocketpcdeploy} directory, which is set to PocketPC My Documents\JavaOnPDAs on the PC. Files copied to PocketPC My Documents are copied to the PocketPC by ActiveSync.

<target name="DeployPocketPC" depends="CompilePocketPC">
  <copy file="${pocketpcdestination}\pocketpc.jar" todir="${pocketpcdeploy}" />
  <copy todir="${pocketpcdeploy}">
    <fileset dir="${pocketpclib}"/>
  </copy>
</target>

Once the JAR file is copied to the PocketPC, we need to create a shortcut to start the Jeode JVM (evm.exe) and run the application. A shortcut file is a text file that looks like this:

18#"\Windows\evm.exe" <command line options> <class name>

For example, to run the application BasicWindow (discussed in a subsequent chapter), we need a shortcut file as follows:

[View full width]
18#"\Windows\evm.exe" -Xnowinceconsole -cp "\My Documents\JavaOnPDAs\pocketpc.jar" com. graphics/ccc.gifjavaonpdas.ui.BasicWindow

The -Xnowinceconsole option indicates to Jeode to not start a Java console. A console would be useful for applications that use System.out.println as a debugging tool. In this case, the option would be -Xwinceconsole.

Another useful Jeode command line option is -Djeode.evm.console. local.keep=TRUE, which tells Jeode to keep the console open after the application has stopped. For other Jeode command line options, refer to Appendix C, "Jeode -D Properties," on page 215 and Appendix D, "Jeode -X Options," on page 221.

To create a shortcut file, the Ant build file includes a CreateShortCuts target, which creates a shortcut for each application in the book.

As an example, the following line from the CreateShortCuts target creates the BasicWindow shortcut described above:

[View full width]
<echo message="18#&quot;\Windows\evm.exe&quot; -Xnowinceconsole -cp &quot;\My Documents\ graphics/ccc.gifJavaOnPDAs\pocketpc.jar&quot; com.javaonpdas.ui.BasicWindow" file="${pocketpcshortcuts}\ graphics/ccc.gifBasicWindow.lnk"/>

This creates the shortcut file on the PC, but it is not yet on the PocketPC. Files with .lnk extensions cannot be copied to the PocketPC through the PocketPC My Documents directory as we did with the JAR file, so we need to copy the shortcuts to the JavaOnPDAs directory in Mobile Device directly. This is done in Windows Explorer by opening the tree under Mobile Device and copying the .lnk file to the JavaOnPDAs folder. Figure 3.5 shows an example view of the folder structure under Mobile Device.

Figure 3.5. The Mobile Device tree in Windows Explorer

graphics/03fig05.gif

The application can then be started on the PocketPC by tapping on the shortcut.