0
public static void main(String[] args) { 

portList = CommPortIdentifier.getPortIdentifiers();

    while (portList.hasMoreElements()) {
        portId = (CommPortIdentifier) portList.nextElement();
        if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
             if (portId.getName().equals("/dev/cu.usbserial-FTCC026H")) {
                 System.out.println("Connecting.....");
        //                if (portId.getName().equals("/dev/term/a")) {
                 ReadReadings reader = new ReadReadings();
             }
        }
    }
}
public ReadReadings() {
    try {
        serialPort = (SerialPort) portId.open("ReadReadings", 1000);
    } catch (PortInUseException e) {System.out.println(e);}
    try {
        inputStream = serialPort.getInputStream();
    } catch (IOException e) {System.out.println(e);}
try {
        serialPort.addEventListener(this);
} catch (TooManyListenersException e) {System.out.println(e);}
    serialPort.notifyOnDataAvailable(true);
    try {
        serialPort.setSerialPortParams(9600,
            SerialPort.DATABITS_8,
            SerialPort.STOPBITS_1,
            SerialPort.PARITY_NONE);
        try {
            inputStream = serialPort.getInputStream();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();serialPort.close();
        }
        br = new BufferedReader(new InputStreamReader(inputStream));

    } catch (UnsupportedCommOperationException e) {System.out.println(e);}

    readThread = new Thread(this);
    readThread.start();
}

public void run() {
    try {
        Thread.sleep(10000);
       if(inputStream != null)
        {
            serialPort.close();
            try {
                inputStream.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            serialPort.close();
            ConnectToHardware.frame.dispose();
        frame = new DisplayReadings();
        //frame.pack();
        frame.setVisible(true);

        }

    } catch (InterruptedException e) {System.out.println(e);serialPort.close();} 
}
public void serialEvent(SerialPortEvent event) {
    switch(event.getEventType()) {
    case SerialPortEvent.BI:
    case SerialPortEvent.OE:
    case SerialPortEvent.FE:
    case SerialPortEvent.PE:
    case SerialPortEvent.CD:
    case SerialPortEvent.CTS:
    case SerialPortEvent.DSR:
    case SerialPortEvent.RI:
    case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
        break;
    case SerialPortEvent.DATA_AVAILABLE:
       // byte[] readBuffer = new byte[1024];
       // String temp = "";

        try {
            String inputLine=br.readLine();

            series.put(num, inputLine);
            num++;
            System.out.println(inputLine);

        }

        catch (IOException e) {System.out.println(e);}
        break;
    }


}
}

I need to create runnable jar file of my project which include 3 classes, external rxtx library and librxtxSerial.jnilib in project.But when creating runnable jar file this librxtxSerial.jnilib file in not included in jar file . I think this is the reason of not getting output when run jar file.

Martin Frank
  • 3,445
  • 1
  • 27
  • 47
krishna
  • 1
  • 5
  • show your code, otherwise ppl cannot help – Donald Wu Oct 26 '16 at 05:52
  • I Added my code but need to create jar file so that i can run without IDE. I am using eclipse. I want that double click on jar file would run my program.Thanks.Its working perfectly in eclipse but not runnable jar file. – krishna Oct 26 '16 at 06:03

1 Answers1

0

JNI libs are loaded by the operating system. Thus, they can't be loaded from a jar file directly. They are loaded from the file system (see java.load.path for details).

You can try to integrate an installer in your java code, which copies the lib from the jar file into the file system before loading the native code.

Community
  • 1
  • 1
clemens
  • 16,716
  • 11
  • 50
  • 65
  • Thanks for help. But I am not getting the part of integration an installer. which installer is free as i am doing this project as a individual so i don't want to spend money to buy installer for project.I really appreciate your help. One more thing include path name of my serialLib(exe file )in argument tab will solve my problem. – krishna Oct 26 '16 at 06:27
  • It's not a full installer. I meant just a method, which copies the data of the jni lib from the jar file to the file system. I think this can be done with less than 20 lines of code. – clemens Oct 26 '16 at 06:35
  • Can you give me the link of that code as i want to provide jar file to my client so that he can use it by clicking it not by command line. – krishna Oct 26 '16 at 11:24
  • If I add JNI lib in native library folder.will it work and how – krishna Oct 26 '16 at 12:06