Hey everyone :)

I'd like to write a J2ME application (my first, as you might have deduced from the post title :P) that lets me connect over Bluetooth using L2CAP from one phone to another so I can send data back and forth between the two. After browsing around and looking at a few code examples I proceeded to begin installing a development framework.

First I tried installing the official JDK, with WTK 2.5.2 since the Java ME toolkit no longer (!?) supports Linux. (O.o)
That didn't work; for whatever reason JSR 82 wouldn't load, and I feel like figuring out why would be akin to diving into quicksand mixed with molasses while blindfolded and with no idea of which way is up. (:P.) I've actually wound up using JDK 1.6.0_24, after trying jdk-7u21 and jdk-6u45 with no success (I was progressively going back in time just in case that placated WTK, which it didn't, and I didn't bother to roll it back to the future again).

After a little digging I soon found MicroEmu and... ah, BlueCove includes an emulator. Awesome :D
So I fire MicroEmu up (and it actually loads respectably quickly :P) and attempt to test the BlueCove library.

Java Code:
$ ./jdk1.6.0_24/bin/java -Dbluecove.emu.rmiRegistryPort=1337  -Dbluecove.emu.rmiRegistry=true -Dlog4j.debug=true -Dlog4j.defaultInitOverride=true    -Dbluecove.debug=true -Dbluecove.stack=emulator -cp log4j-1.2.17.jar:microemulator-2.0.4/microemulator.jar:bluecove-2.1.0.jar:bluecove-gpl-2.1.0.jar:bluecove-emu-2.1.0.jar org.microemu.app.Main  --impl com.intel.bluetooth.BlueCoveImpl ~/j2mewtk/2.5.2/apps/BluetoothDemo/bin/BluetoothDemo.jar
arguments [[--impl], [com.intel.bluetooth.BlueCoveImpl], [/home/i336/j2mewtk/2.5.2/apps/BluetoothDemo/bin/BluetoothDemo.jar]]
initialize implementation [com.intel.bluetooth.BlueCoveImpl]
log4j: Default initialization of overridden by log4j.defaultInitOverrideproperty.
BlueCove log redirected to log4j
openJar [file:///home/i336/j2mewtk/2.5.2/apps/BluetoothDemo/bin/BluetoothDemo.jar]
openJar [file:///home/i336/j2mewtk/2.5.2/apps/BluetoothDemo/bin/BluetoothDemo.jar]
04:25:20.214 Java 1.4+ detected: 1.6.0_24; Java HotSpot(TM) Client VM; Sun Microsystems Inc.
log4j:WARN No appenders could be found for logger (com.intel.bluetooth).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
04:25:20.535 BluetoothStack selected emulator
04:25:22.845 Emulator RMI Service listening on port 1337
>> [1 minute later]: error Can't initialize bluetooth: javax.bluetooth.BluetoothStateException: Connection refused to host: localhost
all 1 thread(s) finished
It just doesn't seem to be able to see the local server. I have no firewall running or anything of that sort, no custom iptables rules, etc.

After asking on IRC I was suggested to try strace-ing java, which I did, but that just made me more confused... internally, Java can bind() the connection (ie create the server side) - to be specific if I try to run eg "nc -l localhost 1337" I'll get an error - but it doesn't seem to be able to connect to the port. I tried disabling IPv6 and while I was able to disable it (strace showed it was using that made no difference. Here are the relevant bits from the strace log in IPv6 mode (the 1337 bit was to make it easier to grep for the requisite info :D):

Java Code:
7056  22:19:12.658648 socket(PF_INET6, SOCK_STREAM, IPPROTO_IP) = 18
7056  22:19:12.658838 setsockopt(18, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
7056  22:19:12.659592 bind(18, {sa_family=AF_INET6, sin6_port=htons(1337), inet_pton(AF_INET6, "::", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = 0
7056  22:19:12.660872 listen(18, 50)    = 0
7056  22:19:15.091037 connect(22, {sa_family=AF_INET6, sin6_port=htons(1337), inet_pton(AF_INET6, "::ffff:", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28 <unfinished ...>
7056  22:20:18.218755 <... connect resumed> ) = -1 ETIMEDOUT (Connection timed out)
In case I missed something the whole strace log can be downloaded from here, if it's relevant: https://www.box.com/s/r60hg9j8pw09ucjugusr (800K, expands to 17MB (!!))

After a bit of pondering I decided to try BlueSim, a commercial/"test-ware" Bluetooth simulator, as a last resort. strace-ing that shows that the underlying emulated device-to-device connection is made but with the example server waiting for connections, the example client decides that hasn't found any valid services.

I tried to get JamVM working to use another JVM but GNU Classpath refuses to work for me (I can't figure out how to get it to build, and using a prebuilt glibj.zip segfaults JamVM - with -verbose it loads a few things, so it does work, but it crashes).

So there you go. I started this morning, around 7 AM... it's now around 8 PM as I post this and I'm still stuck with no development environment.

I'm basically saying... I want "a J2ME development/compilation environment with bluetooth emulation for Linux so I can test/prove my connection code". I honestly don't mind whatever provides this functionality, as long as it runs (!!).

I'm really looking forward to your replies. :)