How to use new Java wrapper? | LabJack
 

How to use new Java wrapper?

6 posts / 0 new
Last post
brianT
btremaine's picture
How to use new Java wrapper?

My old code/Netbean project from 2014 does not run with the new UD drivers. What java wrapper is used in place of LJUDJava.jar?

I'm running on a Windows 10 64-bit system with Netbeans 8.2 from the Oracle Netbeans/Java bundle: jdk-8u161-nb-8_2-windows-x64

My U6 hardware version is V2.00. Does this need new firmware?

Here is the error message in Netbeans from my latest build attempt:

Native code library failed to load.
java.lang.UnsatisfiedLinkError: no LJUDJava in java.library.path
C:\Users\btrem\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)

Thanks,

brianT
btremaine's picture
Update, star date 3/3/2018,

Update, star date 3/3/2018, when using the java/netbeans install bundle jdk-8u161-nb-8_2-windows-x64, and running the compile_and_run.bat file in the Java_LJUD_2015_04_27 driver folder for example Simple.java the code does compile and run okay on my UE9.

My Netbeans project file that ran long ago gets errors in the IDE build on all the imports: import com.labjack.labjackud.LJUD;

brianT
btremaine's picture
Update stardate 3/4/2018.

Update stardate 3/4/2018.

My old Netbeans project (circa 2013) using Labjack used a file named LabjackIO.java. Now that I have successfully pointed my project to the jna.jar and ljud.jar files I am getting farther along. Now I get a lot of errors in the LabjackIO.java file:

        System.out.println("UD Driver Version = " + formatter.format(LJUD.GetDriverVersion()));
        System.out.println("LJUDJava JNI Version = " + formatter.format(LJUD.LJUDJAVA_VERSION) + "\n");
        
        //Open the first found LabJack UE9.
        Errorcode = LJUD.OpenLabJack(LJUD.LJ_dtUE9, LJUD.LJ_ctUSB, "1", 1, Handle);

and almost all references to global error constants are flagged as error, i.e,         if (Errorcode != LJUD.LJE_NOERROR

In the post 2015 java wrapper is there an alternate file in place of LabjackIO.java? 

Thanks,

 

 

brianT
btremaine's picture
This is maybe my 3rd update

This is maybe my 3rd update but my first two updates haven't posted yet.

I can now build the program Netbeans 8.2 with no reported errors but when it runs I get the following error:

      Native code library failed to load.
     java.lang.UnsatisfiedLinkError: no LJUDJava in java.library.path

In my Netbeans project window under Libraries I do have jna.jar and ljud.jar. These are in a subfolder of Java_LJUD_2015_04_27.

My project does not have any links to files in C:\Program Files (x86)\LabJack\. Do I need something here?

Also my project does not have any links to any Labjack DLL files. Do I need something here?

Again, I can execute the U6 and UE9 examples from the command line but if I try:

C:\Users\btrem\NetBeansProjects\LabPoly\dist>java -jar "LabPoly.jar" 

I get the error:
     Native code library failed to load.
     java.lang.UnsatisfiedLinkError: no LJUDJava in java.library.path

Thanks,

 

brianT
btremaine's picture
Update,

Update,

The failure to load LJUDJava.jar was my error. This was left over code from my 2013 project. The code now builds and runs, displaying a GUI window but now I have an invalid handle error to debug. I think I now have Netbeans 8.2 configured properly and compiling using the jna.jar and ljud.jar files from the Java_LJUD_2015_04_27 driver package.

I think from here it is an unrelated problem to the original java wrapper question. I'll post a follow-up if it is related.

Brian

LabJack Support
LabJack Support's picture
ljud.jar and jna.jar are the

ljud.jar and jna.jar are the two Java libraries provided in the Java interface from the Java_LJUD_2015_04_27.zip. It is the current Java interface we support. and has 32-bit and 64-bit support.

LJUDJava.jar and LJUDJava.dll are the Java library and JNA dll from the LJUDJava.zip download. It is our older interface which we no longer update, and only supports 32-bit Java.

Regarding LabjackIO.java, that is not a code provided by us.

In the ljud.jar library, functions throw LJUDException exceptions instead of returning a the error code value. Error code constants are in the LJUD.Errors enum. The examples demonstrate handling the exception.

Your current error indicates that the old LJUDJava.dll is trying to be loaded. Here are two solutions to consider:

1. Use a 32-bit JDK and JRE for building and running your application. You can continue to use your previous code, and our older Java jar and dll. Note that LJUDJava.dll is not compatible with 64-bit Java, and your JDK is 64-bits.

2. Use the current ljud.jar and jna.jar, and update you LabJack related code to use the functionality from ljud.jar. Remove the loadLibrary call for LJUDJava to prevent the java.lang.UnsatisfiedLinkError error.