javabluetoothbluecove

NoClassDefFoundError using bluetooth in java


I asked a question earlier here: NoClassDefFoundError with bluecove's javax.microedition but got no responses.

I am trying to run some java code (Server.java) that requires bluetooth, so I installed the bluecove-2.1.0.jar file in C:\Program Files\Java.

I compile my code with javac -cp "C:\Program Files\Java\bluecove-2.1.0.jar";. Server.java and run it with java Server -cp "C:\Program Files\Java\bluecove-2.1.0.jar"

It compiles successfully, but when I run it, I get the error:

Error: A JNI error has occurred, please check your installation and try  again
Exception in thread "main" java.lang.NoClassDefFoundError: javax/microedition/io/Connection
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.privateGetMethodRecursive(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.microedition.io.Connection
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 7 more

Any ideas where i've gone wrong?

EDIT: Following Minus' answer, to fix the error that followed, I also needed to use a different .jar file which I downloaded from http://snapshot.bluecove.org/distribution/download/2.1.1-SNAPSHOT/2.1.1-SNAPSHOT.63/


Solution

  • The problem is that the .dll is not loaded correctly.

    The library should contain a .dll that will be saved on disk and loaded, maybe the program cannot save the .dll to disk or cannot read it.

    Extract the .dll and follow bluecove installation instructions on Native Library location.

    For example:

    Create a directory c:\blue, and a directory blue\lib.

    Put the files like this:

    C:\blue\Sever.java
    C:\blue\Sever.class
    C:\blue\[bluecove_native_library].dll
    C:\blue\lib\bluecove-2.1.0.jar
    

    Open a cmd (Command Prompt) on c:\blue

    Try to run the app like this:

    java -cp .;lib\bluecove-2.1.0.jar -Dbluecove.native.resource=false Server
    

    This way you will have both Server.class and bluecove-2.1.0.jar in classpath and the DLL in path (since on Windows the current dir is in path).