Using Java on the Pocket PC - the complete tutorial

Discussion in 'Windows Phone' started by Menneisyys, Jun 26, 2005.

Thread Status:
Not open for further replies.
  1. Menneisyys

    Menneisyys Mobile Deity

    Messages:
    2,588
    Likes Received:
    0
    Trophy Points:
    198
    Java is a hugely popular programming language with millions of programmers worldwide. It has a lot of advantages over traditional programming languages like C or C++ and some ever over C# (even when the latter has certainly eliminated some of Java's shortcomings and is definitely better for developing programs targeted at a specific platform like the Pocket PC).

    Sun has made a major mistake when they stopped developing (please read this thread on this subject) its free PersonalJava implementation. Furthermore, Microsoft has never provided any JVM (Java Virtual Machine; the environment to run Java programs) for the Pocket PC platform either. This means we have to rely on third-party JVM's to run our Java programs on.

    Fortunately, especially with some degree of hacking, these third-party JVM's are much more powerful and versatile than you would think.

    What can I do with them? Are they more than just environments to run silly 'dancing letters' applets?

    Yes, they are! In cases, they are very important to have. The most important example that comes into mind is the toonel.net client. Toonel.net is a free service to reduce Internet bandwidth usage. Please read my tutorial on setting it up on PPC devices.

    There're other examples too. For example, I've released a few tools for the Pocket PC's to, for example, to create your own custom word dictionary, to extract embedded sound (WAV) files from Pocket Notes (PWI) files or to demonstrate the NetFront DST problem.

    Also, as there is no decent compiler for the PPC platform. Forget the not-even-C-compliant PocketC, which requires the programmer to learn a completely new, WindowCE-specific - you can't use the experience you've gained anywhere else, unlike with Java or C#! - language & class library. It's just a toy if you compare it to the C# and the CF combo or Java, especially if you take into account the need for learning a new library and being developed by a small developer firm compared to Microsoft or Sun.

    There may be a lot of situations you need to do some specific task on your PDA (for example, writing/modifying a rudimentay HTTP proxy that deletes/modifies some HTTP headers or kills some ad HTTP requests to save bandwidth - this kind of coding can be finished by an experienced Java programmer in a few minutes and you really don't need a desktop computer for this) you can't do in popular scripting languages like MortRunner and you don't want to use any desktop computer emulator (for example, PocketDOS) on your PDA to write a non-native solution to do the stuff either.

    With Java, even program development and compiling are certainly possible.

    What JVM's are available now?

    Not many, but, fortunately, more than for the Palm OS, also with great hackability and real J2SE-compliance (unlike with plain CLDC/MIDP solutions).

    Insignia/Esmertec Jeode:

    this JVM is not sold any more except for the overly expensive Jbed version. Because this JVM was freely shipped with a lot of iPAQ devices and can be installed on any kind of PDA's, you may still want to use it. I certainly recommend it if you still have it lying around on some of your old iPAQ CD's.

    I really recommend this JVM if you still have it. It works great in almost all situations (with toonel, my tools or as a compiler) and has a very good 'hackability' factor.

    Installing it is pretty starightforward. If you install an old(er), but still perfectly usable version like 1.7.3, you may need to relocate it into a storage card because this version will only install to the main memory. You can relocate it to any card if you, after installing it, go to the \Windows directory and move Jeode.evm, evmawt.dll, evmcore.dll, evmpie.dll, iepluginvm.exe, hwawt.dll, javalib.dll, jdwp.dll, math.dll, net.dll and evm.exe from there to the new destination on yoru card. Make sure you also move the \Windows\lib subdirectory in there, so that the files that were in \Windows\lib are in a subdirectory called \lib in the new directory, just under the above-listed files. (I've also described this relocation here.)

    As with all the two other major JVM versions (J9 and CrEme), it has no registry entries so you can freely relocate it and/or just copy it from one device to another. This also means that you can have several versions of Jeode (or, for that matter, J9 and CrEme) on the same device - they won't interfere in each other. This is definitely a big plus, especially if you compare the capabilities of different versions of the same JVM and you don't want to do this on two different PDA's.

    IBM J9, Personal Profile 1.0:

    (please do not mistake it for the IBM J9, MIDP 2.0 version. The latter can't be used for running standalone applications. It only has Midlet support. To find out more about using it for running Midlets, please read this thread.)

    This is a very cheap (US$ 6) JVM, which also has a trial version. Excellent for running Java applications, even toonel. Its hackability factor is, however, much less than that of CrEme or Jeode. It can't function as a compiler either. For running already-made programs that only use Java 1.1, however, it's great. It's easily relocatable and also survives even a hard reset if installed on a memory card, just like with the other major JVM's.

    CrEme:

    a very fast (especially at compiling other programs, compared to Jeode) JVM. It renders AWT widgets/text different from Jeode/J9 though, which may be a showstopper in cases like running it on a VGA device.

    It currently has two versions: the PersonalJava (that is, JDK1.1.8) -compliant 3.x (3.26 is the latest) and the CDC1.1/MIDP1.0-compliant 4.x (currently in beta stage; 4.0b8 is he latest build). Which of the two? Most apps (including the compiler) will run using the stable 3.x versions. Furthermore, I've been unable to made toonel work with the current 4.0 beta version. Therefore, you needn't to run to pick the latest beta instead of a stable build.

    Can be used for compiling programs and has a good 'hackability' factor.

    A little bit of warning: if you execute the installer app on a desktop Windows that has a localized \Program Files directory (for example, the German Windows, which has \Programme instead), the installer will fail (this bug has been noticed also by me). This is a bug still present in the latest, 3.26/4.0b8 versions. You MUST run the installer app on a Windows version that uses the standad \Program Files directory name.

    NetFront JVM:

    this JVM comes with the Java-enabled NetFront Web browser. As of version 3.1 (I haven't tested the JVM shipped with version 3.2 yet, but, hopefully, will manage to do it in a few days), this JVM can be used to run some standalone programs (but definitely not all of them - it didn't run, for example, my ).

    Its 'hackability' factor is pretty low (again, see my posts on compilation at Pocket PC Thoughts); it can't really be hacked to run my NetFront DST problem demo.

    Installing

    The three stand-alone JVM's are very easy to install. J9 and CrEme can be installed straight to a memory card; older versions of Jeode must be relocated to there manually (it, again, isn't complicated at all). The JVM in NetFront gets installed with the NetFront browser - you don't need to install it by hand. (And, incidentally, you don't need to enable it inside NetFront either.)

    After installing the given application, it's ready to run anything.

    Running applications in Pocket PC JVM's

    Applications mostly come in JAR files. (For the Java-savy: you can also run individual class files in the four JVM's too. I've described this in my compilation-related article. This is best used if you also compile your Java programs on your PDA and . However, because most Java programs are distributed in a JAR file, to keep things simple, I only explain how JAR's should be run.)

    You'll need to put the absolute path (for example, \jars\someApp.jar) of these JAR files in the so-called 'classpath' variable, which you pass to the JVM executable file described in the next paragraph.

    Just like with any Pocket PC program, JVM's also have an EXE file to run. You must supply the JAR file path and the class that must be run to this program. The four JVM's need to be invoked the following way from the standard WindowsCE .lnk (link) files:

    Jeode:
    255#"\<path to home directory>\evm.exe" -Djeode.evm.console.local.keep=true -cp <full JAR file path> <main class name>

    CrEme:
    255#"\<path to home directory>\bin\CrEme.exe" -Ob -classpath <full JAR file path> <main class name>

    IBM J9:
    255#"\<path to home directory>\bin\J9.exe" "-jcl:ppro10" -cp <full JAR file path> <main class name>

    NetFront:
    "255#"\<path to home directory>\jvlite.exe" -classpath <full JAR file path> <main class name>

    You can create these link files by hand if not supplied. They only should contain one row - the one that has just been shown. You can put these .lnk files anywhere in your \Windows\Start Menu\Programs directory - they will behave like a "real" link file, just like the ones Windows CE is shipped with.

    The <path to home directory> is, for example, \Program Files\NetFront3\ with NetFront 3.1 installed into main memory, \Windows with Jeode installed into main memory, \<card name>\IBM PPRO10\ with IBM J9 installed into a storage card etc. You can easily find it with Pocket File Explorer or, even better, from the desktop using Total Commander with the WinCE file system plug-in.

    That is, if you decide to store your something.jar file in, say, \SD Card\something.jar, you'll need to pass "\SD Card\something.jar" (notice the " marks! They are needed if the path contains a space like in "SD Card"!) as the <full JAR file path> parameter.

    The second parameter passed to the JVM exe file is the name of the main class. With my programs, it's exactly the same as the JAR name. With, for example, toonel, it's gui.ClientForm. (For the Java-savy, you can't use the well-known <JVM exe name> -jar jarfilename execution form with any of the JVM's). If you are unsure/don't know this, rename the JAR file to a ZIP file and go into it with, say, Total Commander, Go to the META-INF subdirectory and read the MANIFEST.MF file in there. It'll contain something like this:

    Manifest-Version: 1.0
    Main-Class: gui.ClientForm


    You'll need to pass the JVM EXE file the value that stands after the Main-Class attribute; that is, gui.ClientForm in this case.

    Please note that you will need to switch to the console mode with command-line batch variable support if you want to invoke your Java applications with varying parameters. You can pass parameters to your applications in your link files (the parameter(s) come(s) just after the main class name), but if you need to run your application on several different files to be processed (see for example my embedded-sound-PWI or user.dic-to-WinCE-wordlist converter), you may be better bite the bullet and install/get familiar with a console environment like PPC Command Shell, also described in my Java compiling-on-the-PDA article.

    The most important links on other tutorials/forums:

    Java on PocketPC, the Unofficial FAQ - perhaps the best and most up-to-date article/FAQ on PPC JVM's

    The focal point of Pocket PC & Java-related discussion

    Some other links (not as recommended as the two above!):

    Java Support on Pocket PC - a heavily outdated article; it contains a lot of links to non-exisiting JVM's.
    Java On Pocket PC Devices, Mikko Kontio - only discusses a small subset of running full-fledged Java apps on the PPC; still, may be worth reading for some
    JAVA for PocketPC PDA's - one of the most detailed articles (next to the Unofficial FAQ linked as first) on recent JVM's.
     
  2. Menneisyys

    Menneisyys Mobile Deity

    Messages:
    2,588
    Likes Received:
    0
    Trophy Points:
    198
    While evaluating Pocket Mechanic in the Utilities /Maintenance category (I will publish a detailed roundup of these apps in the near future, so, stay tuned :) ) during the Pocket PC magazine Best Software Awards 2005 process, I?ve noticed another bug in CrEme, in addition to the System Path bug, also discovered by me: it registers .jar and .jad files in the Registry without using ? marks when entering the path of creme.exe to the Registry. This will mean the system won?t find creme.exe at all when you click a .jar or a .jad file.

    Curing this problem is very simple: insert " marks before and after the \< home>\NSIcom CrEme\bin\creme.exe string (so that the entire registry value becomes "\\SD-MMCard\\NSIcom CrEme\\bin\\creme.exe" -Of -mv '%1') in both [HKEY_CLASSES_ROOT\jadfile\Shell\Open\Command] and [HKEY_CLASSES_ROOT\jarfile\Shell\Open\Command] .
     
  3. Torgo

    Torgo Mobile Enthusiast

    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Menneisyys,

    You are truly the java god. I have a java issue for the pocketpc that might be useful to many people I know.

    The only thing I can't do on my ppc is 3d modeling, unless you can figure this one out. There is a Java program called JPatch on this site:
    www.jpatch.com

    It is a single jar file that allows modeling and saving to my favorite 3d app, Hash's Animation Master. The folks at Hash told me several times that they won't be writing a pocket version of their modeler, but they won't need to if you can get this to work with some kind of ppc java product. I tried several that you mentioned, but I got many errors that I don't understand.

    Could you please download the jar and try to make it work on the ppc? I would be very grateful. I need a way to model on-the-go since I don't spend too much time sitting at the computer these days.

    Here is a little info from the author of JPatch:

    ---JPatch contains the following 3rd party software:

    ---An 'unofficial' Java3D vecmath package by Kenji Hirabane
    ---see http://objectclub.esm.co.jp/vecmath/

    ---The Xerecs2 XML parser Copyright ? 1999-2004 The Apache
    ---Software Foundation
    ---see http://xml.apache.org/xerces2-j/index.html

    ---BeanShell by Pat Niemeyer
    ---see http://www.beanshell.org

    ---The 3rd party software used in JPatch has not been modified.
    ---For source code
    ---or detailed licensing information please follow the links above.


    Thanks so much for trying to help!
    Andy
     
  4. Menneisyys

    Menneisyys Mobile Deity

    Messages:
    2,588
    Likes Received:
    0
    Trophy Points:
    198
    Unfortunately, it seems it won't work with any of the current JVM's. It's JDK1.4+ only, using Java2D and Swing extensively, which means it won't work with the old Jeode / J9 / CrEme.

    I've tested with the latter two though, just to be on the safe side:

    J9:
    Exception in thread "main" java.lang.NoClassDefFoundError: java.util.prefs.BackingStoreException at java.lang.Class.verifyImpl(Native Method) at java.lang.Class.verify(Unknown Source) at java.lang.Class.initialize(Unknown Source) at jpatch.Launcher.main(Unknown Source)
    CrEme:
    java.lang.NoClassDefFoundError: java.util.prefs.Preferences

    After this, I've tested with the new, free and very promising Mysaifu JVM 0.1.4 (please also see my post here at Sun Sep 18, 2005 6:33 am for more information). Unfortunately, I haven't been able to make it work under Mysaifu either. First, I needed to increase the heap size. After this, I've loaded the missing classes from java.beans to the program's rt.jar. Unfortunately, this didn't make the app work: it kept throwing ClassCastExceptions from buoy.internal.WidgetContainerPanel's. I haven't reverse engineered this class to find out what caused the problem.

    java.lang.ClassCastException: java/awt/Graphics2D
    at buoy.internal.WidgetContainerPanel.paintComponent (WidgetContainerPanel.java:45)
    at javax.swing.JComponent.paint (JComponent.java:1454)

    The oldest version of this app is still JDK1.4+. I've also tested it under Mysaifu. It displayed almost the same (only the memory addresses were different) error (native exception/ attempted to read address.... ) dialog as with Toonel (the latter is compatible with almost everything).

    Unfortunately, as this app has no applet version, I couldn't test it under Thunderhawk.

    You may want to ask its author to 'downgrade' it to JDK1.3-only (hopefully the code would need few changes) or, wait until the Mysaifu JVM reaches the level of compatibility when it can run the app.
     
  5. Torgo

    Torgo Mobile Enthusiast

    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
  6. Torgo

    Torgo Mobile Enthusiast

    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Well it look promising. This is what he said for now:

    About pocketpc and Java1.3:
    At present, JPatch uses Java 1.4 (the current Java version is 1.5).
    Some
    parts of JPatch use Buoy (buoy.sourceforge.net) - and some of the
    errors
    in your mail seem to be Buoy related. But I plan to migrate back to
    AWT/Swing. The latest development version also uses OpenGL (JOGL) for
    hardware accelerated graphics, but it does also work without OpenGL
    support.

    The backing-store exceptions are from Java 1.4's preferences feature,
    but I could modify the code to only use it if available (you won't be
    able to save your custom settings with 1.3 then though).

    I'm not sure how much of the code depends on Java 1.4 features, but
    I'll
    have a look at it. I can't promise anything, and it's not got top
    priority, but I'll see what I can do. I'll let you know if I had
    success
    compiling it to 1.3...

    I do not plan to migrate the code to Java 1.5 (yet), so there's a
    chance
    that it will work on your platform once you get 1.4 support.

    ------

    We'll see... thanks Menneisyys !
     
  7. Menneisyys

    Menneisyys Mobile Deity

    Messages:
    2,588
    Likes Received:
    0
    Trophy Points:
    198
    Hot Pocket PC Java news:

    1. The new, 0.1.5 version of the free and very promising Mysaifu JVM has been released today (please also see my post here at Sun Sep 18, 2005 6:33 am for more information). To a certain degree, it's already capable of running Toonel, but, according to the author (didn't have the time to test it myself), is still unstable. It has an experimental function, "floating frame and dialog". If you set following system property, then you can move and resize windows.

    gnu.java.awt.peer.wce.floating=frame,dialog

    I haven't tested this either as yet ? sounds promising though, as, up to now, one of the biggest annoyances with it was that it didn't allow for resizable, relocatable top-level client windows, unlike other JVM's.

    2. I've played with public Jeode versions released after 2001 (that is, over version 1.7.3) and have written a tutorial on its relocation fix. You'll definitely need it if you want to run it from a storage card. The tutorial has been posted to the following PPC sites: PPCT, iPAQ HQ, AximSite, PPC Magazine, FirstLoox, BrightHand.
     
  8. imported_Golfer

    imported_Golfer WOW! That's amazing .....

    Messages:
    269
    Likes Received:
    0
    Trophy Points:
    68
    I would be interested to know if anyone has ever actually managed to get the java component of Lotus Notes email to work?

    I have never managed to get the Notes java applet toolbar to appear. Basically it's the last component to download and provides the essential toolbasr for New Reply Reply All Forward Delete etc.

    I have used Netfront and Thunderhawk but never got it to work, and on previous threads over the years never actually heard whether it has been done?
     
  9. Menneisyys

    Menneisyys Mobile Deity

    Messages:
    2,588
    Likes Received:
    0
    Trophy Points:
    198
    Please see http://www.aximsite.com/boards/showthread.php?t=100055 on this problem.
     
  10. Menneisyys

    Menneisyys Mobile Deity

    Messages:
    2,588
    Likes Received:
    0
    Trophy Points:
    198
    I've posted a detailed review/roundup/ compliance report / tip collection of current, midlet-capable Java environments on the Pocket PC (including some remarks on the midlet-compliance of Netfront 3.2). It's a must for anyone wanting to run midlets (for example, Opera Mini or Mobile Gmaps) on his or her Pocket PC.

    The article can be found at

    Smartphone & Pocket PC Magazine Expert Blog: http://www.pocketpcmag.com/blogs/index.php?blog=3&p=644&more=1
    FL: http://www.firstloox.org//forums/showthread.php?p=50584
    MobilitySite: http://www.mobilitysite.com/forums/showthread.php?p=148245
    PPCT: http://www.pocketpcthoughts.com/forums/viewtopic.php?p=393834
    BH: http://discussion.brighthand.com/showthread.php?s=&threadid=122613
    AximSite: http://www.aximsite.com/boards/showthread.php?t=120659

    Please also see my blog (just search for "java") for my other, new, Java-related posts ? there have been many lately on the new Mysaifu/ CrEme / WM5-compliace reports.
     
Loading...
Thread Status:
Not open for further replies.

Share This Page