Java doesn't find PCANBasic JNI

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
EBiker42
Posts: 2
Joined: Thu 25. Apr 2019, 17:30

Java doesn't find PCANBasic JNI

Post by EBiker42 » Thu 25. Apr 2019, 17:54

Hello,

I'm trying to get the PCAN Java API to work on Linux (Ubuntu 18) with a PCAN USB.
To do so, I downloaded the Peak Linux driver package and the API package(PCAN-Basic_Linux-4.3.1) and compiled + installed them according to the Readme. I installed the libpcanbasic first and then the libpcanbasic_jni, as explained in the Readme. All compilations + installations worked without errors.

The pcanview tool works fine, detects the PCAN and shows the CAN messages as expected. Therefore, the driver seems to be OK.
However, when I try to run any Java application which tries to use the PCAN, it fails because it doesn't find the JNI:

Code: Select all

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no PCANBasic_JNI in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2660)
        at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:829)
        at java.base/java.lang.System.loadLibrary(System.java:1867)
        at peak.can.basic.PCANBasic.<clinit>(PCANBasic.java:294)
        at peak.can.Application.<init>(Application.java:48)
        at peak.can.Application$164.run(Application.java:4637)
        at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
        at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
        at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
        at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
        at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
        at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
        at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
In /usr/lib/, there are the libpcan.so, libpcanbasic_jni.so and libpcanbasic.so files, so I don't understand why they are not found.

In the makefile for libpcanbasic_jni, I tried to set the JAVA_HOME both to an Oracle Java11 and Java8 JDK. Both produce the same result.

Did I miss/overlook something?

Thanks,

Markus

User avatar
S.Grosjean
Software Development
Software Development
Posts: 357
Joined: Wed 4. Jul 2012, 17:02

Re: Java doesn't find PCANBasic JNI

Post by S.Grosjean » Mon 29. Apr 2019, 17:45

Hello,

Looks like there is a mistake in the library name. As a workaround, please, do:

Code: Select all

$ cd PCAN-Basic_Linux-4.3.1/pcanbasic_java/libpcanbasic_jni
$ sudo make NAME=libpcanbasic_jni uninstall
$ make clean
$ make NAME=libPCANBasic_JNI
$ sudo make NAME=libPCANBasic_JNI install
Then retry the example.

Thank you for your feedback.

Best regards,
— Stéphane

F.Vergnaud
Software Development
Software Development
Posts: 305
Joined: Mon 9. Sep 2013, 12:21

Re: Java doesn't find PCANBasic JNI

Post by F.Vergnaud » Mon 6. May 2019, 10:46

Hello,

Alternatively, here is the change to apply on the Java source file PCANBasic.java (in folder peak/can/basic, line 293):

Former version:

Code: Select all

static {
        System.loadLibrary("pcanbasic_jni");        
    }
New version:

Code: Select all

static {
        try {
            System.loadLibrary("pcanbasic_jni");
        } catch (UnsatisfiedLinkError e) {
            System.out.println(e.getMessage());
            System.loadLibrary("PCANBasic_JNI");
        }
    }
Best regards,
Fabrice

EBiker42
Posts: 2
Joined: Thu 25. Apr 2019, 17:30

Re: Java doesn't find PCANBasic JNI

Post by EBiker42 » Wed 8. May 2019, 10:14

S.Grosjean wrote:Hello,

Looks like there is a mistake in the library name. As a workaround, please, do:

Code: Select all

$ cd PCAN-Basic_Linux-4.3.1/pcanbasic_java/libpcanbasic_jni
$ sudo make NAME=libpcanbasic_jni uninstall
$ make clean
$ make NAME=libPCANBasic_JNI
$ sudo make NAME=libPCANBasic_JNI install
Then retry the example.
Sorry for the late answer. I tried it now, and it works perfectly!
Many thanks!
F.Vergnaud wrote:Alternatively, here is the change to apply on the Java source file PCANBasic.java (in folder peak/can/basic, line 293):
Also thanks for this suggestion! I didn't try it however, since I'm also using the PCAN with existing Java applications which I don't want to change.

Best regards,

Markus

TheWP
Posts: 1
Joined: Thu 7. May 2020, 17:49

Re: Java doesn't find PCANBasic JNI

Post by TheWP » Thu 7. May 2020, 17:51

Under Windows for the NetBeans project, the following worked for me:

1. Right click on the Project
2. Properties
3. Click on RUN
4. VM Options : -Djava.library.path="<FULLPATH TO Samples\JAVA\32-bit or 64-bit, depending on environment>"
5. Click Ok

However, I think this will hard code the same path into your project, so these DLLs should actually be installed in one of the directories in your system environment paths.

Post Reply