For Java Programmers: Executing External Applications, Accessing Web Resources and Initiating Browser Redirection from Java Code

Topics:

http://smartphonemag.com/forum/topic.asp?TOPIC_ID=20454

(Also see this question) A common question from Java programmers is whether you can execute an external application from a Java self-standing application (that is, not an applet) on the Pocket PC. In this article, I scrutinize this question, along with the Pocket PC support of applets communicating with applications on the originating host and redirecting the browser to another page. The short answer to the first question is: no. The long answer is as follows: I've tested all the current (or, with Jeode, the latest available) Java Virtual Machine versions with an application that should have started Pocket Excel (application class file, compiled with JDK 1.1 so that even Jeode can load it, here; source here and JAR file with the class here). The test results are as follows:
  1. CrEme 4.00 beta: doesn't work
  2. Mysaifu 1.0.9: doesn't work The error message shown (note that the current version of Mysaifu likes referring to the user class to be missing (ClassNotFoundException) when some of the related classes/their method are missing; in this case, the situation is the same): java.lang.ClassNotFoundException: Execute not found in java.lang.ClassLoader$1{urls=[file:/e.jar], parent=null} at java.net.URLClassLoader.findClass (URLClassLoader.java:870) at java.lang.ClassLoader.loadClass (ClassLoader.java:342) at java.lang.ClassLoader$1.loadClass (ClassLoader.java:1110) at java.lang.ClassLoader.loadClass (ClassLoader.java:294) at java.lang.VMMainThread$1.run (VMMainThread.java:96) at java.lang.VMThread.run (VMThread.java:120) JVM exit.
  3. IBM J9 PE: doesn't work The error message shown: (W)J9VM0013 Initialization error in function VMInitStages: (E)J9VM0009 J9VMDllMain failed (E)EXEX0013 Internal VM error: Failed to create Java VM (I)EXEX0014 Run -help for usage
  4. the latest, version 1.9.3 Esmertec Jeode JVM (no longer directly sold): doesn't work (another screenshot scrolled to the right so that you can see the rest of the Exception report is here).
The same stands for running local Pocket PC applications from a Java applet: even if you sign the applet (which isn't possible with, to my knowledge, at least the Jeode PIE plug-in) and, therefore, by getting out of the applet "sandbox" and would be allowed to run such a "dangerous" operation, the lack of, for example, the necessary classes in CrEme will result in the applet's being unable to run any external application. Note that I haven't checked the NetFront 3.2 JVM in this respect; I don't think, its being much more constrained than Jeode/CrEme that it'd work. Finally, Thunderhawk, which has decent, but proxy server-side Java-support: as it's not the browser that executes Java but a server computer somewhere on the Internet (it's working like Server-Based Computing, on a much smaller scale), it won't be able to access/run local Pocket PC applications either. Other kinds of Java applet-based networking connections, however, will work. The most important of them is an applet communicating with dynamic applications on the originating host (for example, a Java servlet or a PHP script). I've tested this with input streams (assuming you can send all the dynamic parameters to the servlet in the URL, as GET or POST parameters, so you don't really need streams in both direction - that is, I haven't tested outgoing streams) and all Java-enabled browsers on the Pocket PC worked OK. Screenshots of this (note that I haven't made screenshots of the previous case because simple Java applet-based redirection isn't shown on the screen): Jeode 1.9.3 (run on a iPAQ 5550 – had to run it on there because it's locked to iPAQ 5550's) Thunderhawk 2.1 (on a VGA device – yes, it's THAT bad on VGA Pocket PC's) CrEme 4.00b8 NetFront 3.2 (Note that the current (both beta) versions of Opera and Minimo don't support Java applets at all.) You can too check this with this applet. The applet source can be found here. If you are unsure about applet-based communications / need more info on them, I heartily recommend Chapter 10, Applet-Servlet Communication, in Jason Hunter's excellent book Java Servlet Programming, Second Edition. Incidentally, I've also tested redirecting the browser to a Web page using java.applet.AppletContext.showDocument(). It will work with almost all Java-enabled browsers. Thunderhawk (TH) 2.1, NetFront (NF) 3.2 with the JVM plug-in and CrEme 4.00b8 all worked; it's only Jeode 1.9.3 that didn't. The latter didn't show any error message. You can too check this with this applet. The applet source can be found here. It will, after waiting two seconds, redirect the browser to my homepage.

Give a try to Thunderhawk. Unfortunately, the "traditional" (Jeode/CrEme) PIE plug-ins are both 1.3 only.

"Does anybody know if there's a small .NET- or Win32-App for PPC which like runs a socket which takes the path of an application and executes the application it?"

What did you mean by "runs a socket"? Simply executing an external application? Or, does it listen to incoming TCP/IP requests by keeping a server socket open?

If plain execution is what you meant, you may also want to give a try to nScriptm, a free, great scripting solution for the Pocket PC. I've published some examples of using it to execute external applications here and here.

Java is too heavy-weight for this task, RAM/CPU usage-wise. Besides, it doesn't seem to work.

The best wayt to do this is either native eVC or .NET.

If you, however, want to give nScriptm a try (so that you can avoid using the much more complicated eVC or purchasing isual Studio). It supports both server socket listening and conditional execution - as with any decent programming language/function library. See http://s-k-tools.com/freeware/nsen.txt for more information.

"I have to put my code in a file with
the extension "ns", right? And I
have to register the extension "ns"
with the registry before..."

You can register the .ns extension in the Registry (by using Resco Explorer or MyExtension) - but you don't have to. You can just create a direct link to ns.exe, passing the .ns file as parameter to be executed.

Syndicate content