Other [SOLVED] Using an external jar.

Star-Dust

Expert
Licensed User
Longtime User
I have this source which works fine when compiling with jdk1.8.0_202 (the same one I use with B4J)

Java:
import com.WacomGSS.STU.*;
import com.WacomGSS.STU.Protocol.*;

public class simple2
{
  private void queryUsb()
  {
    com.WacomGSS.STU.UsbDevice[] usbDevices = UsbDevice.getUsbDevices();
    if (usbDevices != null && usbDevices.length > 0)
    {
      System.out.println("Num: "+usbDevices.length);    
    }
    else
    {
      System.out.println("no USB devices found");
    }
  }
  public static void main(String[] args)
  {
    simple2 program = new simple2();
    program.queryUsb();
  }
}

Reproducing a very similar code on b4j with java inline I get an error:
B4X:
#AdditionalJar: C:\Program Files (x86)\Wacom STU SDK\Java\jar\x64\wgssSTU.jar

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
End Sub

Sub Button1_Click
    Dim J As JavaObject = Me
    J.RunMethod("queryUsb2",Null) 
End Sub

#if JAVA
import com.WacomGSS.STU.*;
import com.WacomGSS.STU.Protocol.*;

public static void queryUsb2()
  {
    com.WacomGSS.STU.UsbDevice[] usbDevices = UsbDevice.getUsbDevices();
    if (usbDevices != null && usbDevices.length > 0)
    {
      System.out.println("Num: "+usbDevices.length);
    }
    else
    {
      System.out.println("no USB devices found");
    }
  }
#End If

This can be seen from the logs
Waiting for debugger to connect...
Program started.
Error occurred on line: 23 (Main)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at b4j.example.main._button1_click(main.java:96)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA$1.run(BA.java:236)
at com.sun.javafx.application.PlatformImpl.lambda$null$177(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$178(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$152(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.UnsatisfiedLinkError: no wgssSTU in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at com.WacomGSS.STU.UsbDevice.<clinit>(UsbDevice.java:10)
at b4j.example.main.queryUsb2(main.java:105)
... 27 more
 

Star-Dust

Expert
Licensed User
Longtime User
There is no .so file inside the jar.
The jar uses wgssSTU.dll which is bundled with the JAR.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
...If it uses .dll may be need... jna... to download and import at project too ?
it uses jna and is already there in the B4J add-on libraries.
However the java code works it works correctly it's the b4j one that throws this error as if it can't find the class inside the JAR
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
SOLVED
It was necessary to put the parameters in the #VirtualMachineArgs 😁
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Here is the result



1670346023680.png


ezgif.com-gif-maker.gif
 
Upvote 0
Top