C codie01 Active Member Licensed User Longtime User Jan 17, 2018 #1 I am trying to integrate a jar as an external library into my ABMaterial app to talk to cups print server on linux. I really cannot get my head around this and ask for help. Here is my code so far. Code: Copy Dim printerlist As List Dim cups As JavaObject cups.InitializeStatic("org.cups4j.CupsClient") printerlist = cups.RunMethod("getPrinters", Null ) Log( printerlist ) The first issue is i can not set the ip and user under CupsClient. As an example could someone please show some code to 1) intialise the object and 2) run the "getPrinters" method. The link to the API or Jar is http://cups4j.org/api/docs/api/ The doc I have pasted below. Much Thanks in advance. Last edited by a moderator: Jan 18, 2018
I am trying to integrate a jar as an external library into my ABMaterial app to talk to cups print server on linux. I really cannot get my head around this and ask for help. Here is my code so far. Code: Copy Dim printerlist As List Dim cups As JavaObject cups.InitializeStatic("org.cups4j.CupsClient") printerlist = cups.RunMethod("getPrinters", Null ) Log( printerlist ) The first issue is i can not set the ip and user under CupsClient. As an example could someone please show some code to 1) intialise the object and 2) run the "getPrinters" method. The link to the API or Jar is http://cups4j.org/api/docs/api/ The doc I have pasted below. Much Thanks in advance.
Erel B4X founder Staff member Licensed User Longtime User Jan 18, 2018 #2 getPrinters is not a static method. You must create a new instance with: Code: Copy cups.InitializeNewInstance("org.cups4j.CupsClient", Null) 'there are other constructors available Log(cups.RunMethod("getPrinters", Nulll)) Upvote 0
getPrinters is not a static method. You must create a new instance with: Code: Copy cups.InitializeNewInstance("org.cups4j.CupsClient", Null) 'there are other constructors available Log(cups.RunMethod("getPrinters", Nulll))
C codie01 Active Member Licensed User Longtime User Jan 18, 2018 #3 Thanks Erel, I have changed the code as per following and it throws the following error: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException Code: Copy cups.InitializeNewInstance("org.cups4j.CupsClient",Array("000.000.000.000", 631, "root")) Log(cups.RunMethod("getPrinters", Null)) Upvote 0
Thanks Erel, I have changed the code as per following and it throws the following error: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException Code: Copy cups.InitializeNewInstance("org.cups4j.CupsClient",Array("000.000.000.000", 631, "root")) Log(cups.RunMethod("getPrinters", Null))
Erel B4X founder Staff member Licensed User Longtime User Jan 18, 2018 #4 You should post the full error message. Upvote 0
C codie01 Active Member Licensed User Longtime User Jan 18, 2018 #5 Thanks Again Erel, As a background I am doing this from within ABMaterial. java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119) at anywheresoftware.b4a.BA.raiseEvent(BA.java:77) at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:188) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:748) Caused by: 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:131) at b4j.example.printgenero._getprinters(printgenero.java:172) at b4j.example.printgenero._section0(printgenero.java:308) at b4j.example.printgenero._connectpage(printgenero.java:150) at b4j.example.printgenero._websocket_connected(printgenero.java:447) 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:90) ... 7 more Caused by: java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient at org.cups4j.CupsClient.getPrinters(CupsClient.java:107) ... 21 more Caused by: java.lang.ClassNotFoundException: org.apache.http.client.HttpClient at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 22 more Upvote 0
Thanks Again Erel, As a background I am doing this from within ABMaterial. java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119) at anywheresoftware.b4a.BA.raiseEvent(BA.java:77) at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:188) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:748) Caused by: 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:131) at b4j.example.printgenero._getprinters(printgenero.java:172) at b4j.example.printgenero._section0(printgenero.java:308) at b4j.example.printgenero._connectpage(printgenero.java:150) at b4j.example.printgenero._websocket_connected(printgenero.java:447) 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:90) ... 7 more Caused by: java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient at org.cups4j.CupsClient.getPrinters(CupsClient.java:107) ... 21 more Caused by: java.lang.ClassNotFoundException: org.apache.http.client.HttpClient at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 22 more
Erel B4X founder Staff member Licensed User Longtime User Jan 18, 2018 #6 Your library depends on other jars as well. You need to add all the jars that it depends on. Upvote 0
C codie01 Active Member Licensed User Longtime User Jan 18, 2018 #7 Erel you awesome. Many thanks. There was a jar missing as you stated. There are two required as follows: #AdditionalJar: cups4j-0.6.4 #AdditionalJar: cups4j.runnable-0.6.4 And the code: Code: Copy cups.InitializeNewInstance("org.cups4j.CupsClient",Array("000.000.000.000", 631, "root")) Log(cups.RunMethod("getPrinters", Null)) The log result is: [] At a guess I would say it found no printers, is this right? Many thanks, I really don't know how you do this so tirelessly, impressive! Upvote 0
Erel you awesome. Many thanks. There was a jar missing as you stated. There are two required as follows: #AdditionalJar: cups4j-0.6.4 #AdditionalJar: cups4j.runnable-0.6.4 And the code: Code: Copy cups.InitializeNewInstance("org.cups4j.CupsClient",Array("000.000.000.000", 631, "root")) Log(cups.RunMethod("getPrinters", Null)) The log result is: [] At a guess I would say it found no printers, is this right? Many thanks, I really don't know how you do this so tirelessly, impressive!
Erel B4X founder Staff member Licensed User Longtime User Jan 19, 2018 #8 codie01 said: The log result is: [] At a guess I would say it found no printers, is this right? Click to expand... Yes. It is an empty list. Upvote 0
codie01 said: The log result is: [] At a guess I would say it found no printers, is this right? Click to expand... Yes. It is an empty list.