Bluetooth Deployer
December 31st, 2007 by SamThe test-develop cycle for writing J2ME applications can be significantly slowed down by the need to deploy the application onto the device. Given that most network operators charge extortionate data rates, the only real option is bluetooth deployment. In this post I present a solution that can be included as an Ant task. Note that it might not work for everyone as some operators and handset manufacturers intentionally disable bluetooth deployment of MIDlets.
In OS X, this is as simple as using the Bluetooth File Exchange application and sending both the jar and the jad (so that the digital signature can be used to set the correct permissions). However, this is very repetitive, non-scriptable and platform specific.
It occurred to me recently that the Bluetooth API for J2ME has implementations that work in J2SE… and there is no reason why I couldn’t write a Bluetooth MIDlet Deployer, for use in an ant task. In this post, I’ll give you the source and an example ant task for automating this annoying part of the J2ME development process. The source itself should work as a light introduction to putting multiple files on a device with the OBEX libraries of JSR-82.
Hat tip to Vlad Skarzhevskyy of Bluecove and MicroEmu who tells me that he has been using his Maven task obex-maven-plugin for 2 years.
UPDATE: (16th Jan 2008) This is now split across 3 files. The referenced files are available at BluetoothDeviceDiscover.java and BluetoothServiceDiscover.java. These are part of J2ME library I am working on. The source code to the deployer is available at BluetoothDeploy.java.
First of all, you’ll have to get an implementation of JSR-82. I use Bluecove which works great on OS X and Windows. Avetana is available commercially for OS X. If you use Linux you may wish to check out BlueZ for the latest list of implementations, although future releases of Bluecove will support Linux.
Then you can bundle the 3 classes into a jar (or download my binary bluetoothdeploy.jar), invoking it using the command line
java -cp bluetoothdeploy.jar:jsr82.jar thinktank.j2me.j2se.BluetoothDeploy HWADDR app.jad app.jar
where HWADDR is your bluetooth device’s connection URL. This may be obtained by running the jar without any parameters.
On my phone (RAZR V3i), this works most of the time… but if I have an old copy of my jar/jad saved on the phone, it will throw an error if the jad is the first to arrive, or it will attempt to install the unsigned version if the jar is first to arrive. I typically clear out any old versions from the phone first.
If you’re using Ant, the following task should automate the process for you (make sure your paths are correct for your setup)
<!-- Deploy to a device using Bluetooth -->
<target name="deploy" depends="build">
<java fork="yes" classname="thinktank.j2me.j2se.BluetoothDeploy" classpath="bluetoothdeploy.jar:bluecove.jar">
<arg line="btgoep://0123456789ab:8;authenticate=false;encrypt=false;master=false" />
<arg line="app.jad" />
<arg line="app.jar" />
</java>
</target>
If you’ve set up the build task to build your preverified jar and jad… deployment is a breeze! In my next post, I’ll go into more detail about setting up your IDE (and ant) for J2ME development without the buggy EclipseME.
Note that you can use this for sending any kind of file… I just wrote it with jar/jad specifically in mind.
Vlad wrote:
January 1st, 2008 at 12:35 am