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.

Thanks for the info.

I have been trying to connect my Pocket PC v4.2 via Pocket IE to a networked application on a server that requires Java 1.4.2 on the client.

The closest I came was when I used NetFront 3.2 and the screen came up blank and did not ask for Java 1.4.2

Any thoughts would be appreciated.

Thanks
Mark P.

Werner Ruotsalainen's picture

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

Thanks, I'll give them a try.

Unfortunately I have the same problem
as outlined here.
I must open an application
on Pocket PC from a Java application
running with IBM J9 VM.

So, I tried everything to make this
work with
Runtime.getRuntime().exec(...);
but I reached nothing by trying this.

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?

Even more complicated: the application needs to open a certain
file. I know that the application
is able to open a certain file when
you pass the path of the file as
first parameter on command line...

So are there any hints on how to
accomplish that?

Werner Ruotsalainen's picture

"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.

As far as I can see, you have to run a
script (some *.ns ressource) with
nscriptm. So how can I run a script
from within Java on Win Mobile?

My idea was to implement a little app
which which listens on a
certain port for requests. When a
request arrives it takes the first
argument and tries to execute it (if
this is possible on Win Mobile, I'm
a bit insecure about this now).

Or is there a more elegant version
to start an application? This is a
pure workaround to have communication
from Java with Win Mobile (apps).

That's it.

Thanks,
johannes

Werner Ruotsalainen's picture

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.

nScriptm looks quite cool. seems
to be a wrapper for visual c++.

Have to
see how to bind a socket server to a
certain port and open an app
parameterized. script seems to look like this:

for serversocket:
socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
bind(soc, sockaddr_in);
listen (soc, backlog);
accept (soc);
recv (soc, &buf, len, flags);

for app-execution:
Shell (appName, fileToOpen, pathToApp, style);

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...

Thanks
johannes

Werner Ruotsalainen's picture

"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.

Not strictly to do with the topic, but the error message you received when trying to run IBM J9 PE? Do you know what caused it?

I am getting the same error, but I am not trying to open an enternal resource, a web application or re-directing a browser. I am trying to open a small app that merely accesses the PPC2003 API.

Syndicate content