0

I'm using in my program the bluecove library.
While running the program via eclipse, all works smooth. I'm now trying to deploy my program, and following this post i'm using fat-jar.
When i run the jar file (created by fat-jar), the library can't be located, and i'm getting the exception BlueCove libraries not available as result of this line local = LocalDevice.getLocalDevice();.

In the fat-jar window i tried also to add bluecove-2.1.0.jar to the Class-Path place, and also with the path \src\JoJoServer\bluecove-2.1.0.jar.
I tried also to place the bluecove's jar file in different folders, such as the src, or an external folder.

Although i know it's not recommended, i tried the option of One-Jar, nevertheless it didn't help.

To run the jar (the one created by fat jar) i simply double click the file.
What i'm missing?

This is the entire code:

import java.io.IOException;
import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.UUID;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;

@Override
public void run() {
    // retrieve the local Bluetooth device object
    LocalDevice local = null;
    StreamConnectionNotifier notifier;
    StreamConnection connection = null;

    // setup the server to listen for connection
    try {
        local = LocalDevice.getLocalDevice();
        local.setDiscoverable(DiscoveryAgent.GIAC);

        UUID uuid = new UUID("0000110100001000800000805F9B34FB", false);
        System.out.println(uuid.toString());

        String url = "btspp://localhost:" + uuid.toString() + ";name=RemoteBluetooth";
        notifier = (StreamConnectionNotifier)Connector.open(url);
    } catch (BluetoothStateException e) {
        System.out.println("Bluetooth is not turned on.");
        e.printStackTrace();
        return;
    }

    // ...
}

enter image description here

Community
  • 1
  • 1
Presen
  • 1,809
  • 4
  • 31
  • 46

1 Answers1

0

I have no clue what could be your problem, but I've tried the process and everything works, so just a summary of what I've did. Maybe you will figure it out by following it...

I don't understand how the posted code could be the entire, I see no class definition. :) So I've modified it to the main method and it works both from the Eclipse and also by running the JAR generated by the FatJar.

The modified code of the BTTest class:

package test;

import java.io.IOException;
import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.UUID;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;

public class BTTest {

    public static void main(String[] args) throws Exception{
        // retrieve the local Bluetooth device object
        LocalDevice local = null;
        StreamConnectionNotifier notifier;
        StreamConnection connection = null;

        // setup the server to listen for connection
        try {
            local = LocalDevice.getLocalDevice();
            local.setDiscoverable(DiscoveryAgent.GIAC);

            UUID uuid = new UUID("0000110100001000800000805F9B34FB", false);
            System.out.println(uuid.toString());

            String url = "btspp://localhost:" + uuid.toString()
                    + ";name=RemoteBluetooth";
            notifier = (StreamConnectionNotifier) Connector.open(url);
        } catch (BluetoothStateException e) {
            System.out.println("Bluetooth is not turned on.");
            e.printStackTrace();
            return;
        }

        // ...
    }
}

To run or produce it, I have just put the bluecove library in the build path and created the fat jar with a simple way: http://oi60.tinypic.com/vg1jpt.jpg

Starting the generated jar from command line:

D:\testProjects\bttest>java -jar bttest_fat.jar
BlueCove version 2.1.0 on winsock
0000110100001000800000805f9b34fb
BlueCove stack shutdown completed

Can you post a difference to your process?

MirecXP
  • 443
  • 7
  • 18