Installing a JAR File on a Phone (Part 1)
By seapegasus on Jun 18, 2006
OK, say I have, like, a totally super Java ME application. Admittedly, it doesn't do much: It generates a game map and you can walk throught it one-way, but nothing exciting happens. The project compiles and runs with the NetBeans Mobility Pack default phone emulator, and there's a JAR file in the project's dist directory that contains the complete application (even a JAD info file if I needed it). Perfect. Now, I want to see what the app looks like on my mobile phone. But... how does it get there? =-(
The easiest method is Bluetooth file transfer (or of course a direct USB cable, but I have none). I know how to receive files with Bluetooth in Linux, but I can't send them, since I am missing the sending part on the notebook's side... Of course there's the Nokia PC Suite for that. Alas, it's for Windows only.
Before I install PC Suite, I have another idea: MacOS has an Apache webserver... Can't I just go online, write down my temporary IP address, switch on the webserver, drop the JAR file into
/Library/WebServer/Documents/, and... use the mobile's webbrowser to download the JAR file? I'd need to pay a fee to establish the GPRS connection, but I only want to try it once anyway...
Well 'once', that's what they all say. Of course the first try fails -- the mobile's browser opens the JAR file as text?! (In retrospect, did I use the wrong menu? My Nokia has an extra menu item for installing applications from a URL, but I used the general browser.) So first I need to make sure my webserver assigns the JAR the correct mime type.
Depending on your webserver, you need to find the mimetype configuration settings: For Apache on MacOS this is for instance /private/etc/httpd/mime.types. You need administrator privileges to edit this file. Add these two lines, one for the type and one for the suffix
text/vnd.sun.j2me.app-descriptor jad application/java-archive jar
Don't forget to restart the webserver to activate the change. In MacOS you restart Apache via the Apple Menu > System Preferences > Sharing by stopping and restarting Personal Web Sharing.
And... Yes, the second download attempt works! (This time, I also made sure to use the mobile's Web > Download menu item instead of Web > Go To Address.) The phone offers me now to install and run the JAR file, if I trust it. Oh my, how exciting!
Result? The game runs! Yay! Only... my game screen is bigger than the mobile's actual screen.. :-( The lower half of the map is cut off... Lukas' tip for resizing the emulator screen works fine (thanks!), but I will bother with optimizing the size settings tomorrow. \*yawn\* In part 2 we will see how far I'll get with the PC Suite and Bluetooth. At least I know now my app works. :-) :-) :-)