Jump to content

Stuck adding external libraries to local script for api calls.


CrackplanetsCrac

Recommended Posts

Hello people,

First of all, let me appologise if this has clearly been answered multiple times, i searched all over the forum/google be was unable to really find anything that worked out for me.

So i got a web api running on my server, this web api is connected with an sql server that is being hosted on my server as well.
I can make calls to it and everything so i know it works.
This led me to the point where it was time to implement it into my java scripts, and this is where i (with seemingly many others) hit the issue of using external libraries in or scrips.

From reading all those posts it seems that they are just not allowed in the SDN, but that the usage of them localy should not be an issue. I run my stuff just localy, and don't touch the SDN at all (as far as im aware).

That being said, the code has been written, the artifact has been build, but i am unable to run any of it and just spits out a whole list of errors "Failed to load local script: library class.class".
I tried pretty much everything i was able to find, from adding modules, to extracted libraries in my artifacts, but i seem to be unable to add them, or atleast get Osbot from running the script

For this reason i would like to ask the question if anyone here 'that has used excternal libraries in local scrips before' could give me a rundown as to how its done.
 

For those that are intrested the libraries that i am trying to include are Retrofit2, Okhttp3 and retrofits Gson Converter factory. I got them all as jar files, that being said they are all open source, so i could get my hands on the source files if that needed to get it to work.

 

Link to comment
Share on other sites

@CrackplanetsCrac

Firstly you _can_ use external libraries on the SDN, you will just need to include the source of those libraries in your repository.

As for local scripts, have you tried extracting the dependency to your output .jar?

Example:

Here you can see the library you want to add in the Available Elements section on the right hand side

ss1.thumb.PNG.008c14936afae472d5cf6c8b2b94c9ae.PNG

 

Right click the library and select extract into output root

 

ss2.thumb.PNG.103d025f2c652e1ce468b199323131b3.PNG

 

Now the extracted library will be output to your .jar

ss3.PNG.b2db2a5fd102da05fa732d76c7e61273.PNG

 

And it should work when running your script

  • Like 2
Link to comment
Share on other sites

@Explv

So i got that, and it compiles nicely, i then run osbot through cmd like

java -jar "path/to/osbot/jar" -debug

sadly enough when then checking the script tab the out put it generates gives me alot of complains

Spoiler

[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$ChunkedSource.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/cache/DiskLruCache$2.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/cache/DiskLruCache$Editor$1.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/http2/Http2Codec$StreamFinishingSource.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$FixedLengthSink.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/http/CallServerInterceptor$CountingSink.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$AbstractSource.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/ws/WebSocketWriter$FrameSink.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/cache/FaultHidingSink.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/http2/Http2Stream$FramingSink.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/cache2/Relay$RelaySource.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/Cache$CacheResponseBody$1.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$FixedLengthSource.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$UnknownLengthSource.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/http2/Http2Stream$FramingSource.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/http2/Http2Stream$StreamTimeout.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$ChunkedSink.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/http2/Http2Reader$ContinuationSource.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/Cache$CacheRequestImpl$1.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : okhttp3/internal/cache/CacheInterceptor$1.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : retrofit2/OkHttpCall$ExceptionCatchingRequestBody$1.class
[ERROR][10/11 08:55:38 PM]: Failed to load local script : org/apache/commons/logging/impl/ServletContextCleaner.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : com/thoughtworks/xstream/converters/reflection/CGLIBEnhancedConverter$ReverseEngineeredCallbackFilter.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$ChunkedSource.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/cache/DiskLruCache$2.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/cache/DiskLruCache$Editor$1.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/http2/Http2Codec$StreamFinishingSource.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$FixedLengthSink.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/http/CallServerInterceptor$CountingSink.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$AbstractSource.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/ws/WebSocketWriter$FrameSink.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/cache/FaultHidingSink.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/http2/Http2Stream$FramingSink.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/cache2/Relay$RelaySource.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/Cache$CacheResponseBody$1.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$FixedLengthSource.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$UnknownLengthSource.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/http2/Http2Stream$FramingSource.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/http2/Http2Stream$StreamTimeout.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$ChunkedSink.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/http2/Http2Reader$ContinuationSource.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/Cache$CacheRequestImpl$1.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : okhttp3/internal/cache/CacheInterceptor$1.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : retrofit2/OkHttpCall$ExceptionCatchingRequestBody$1.class
[ERROR][10/11 08:55:39 PM]: Failed to load local script : org/apache/commons/logging/impl/ServletContextCleaner.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : com/thoughtworks/xstream/converters/reflection/CGLIBEnhancedConverter$ReverseEngineeredCallbackFilter.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$ChunkedSource.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/cache/DiskLruCache$2.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/cache/DiskLruCache$Editor$1.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/http2/Http2Codec$StreamFinishingSource.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$FixedLengthSink.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/http/CallServerInterceptor$CountingSink.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$AbstractSource.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/ws/WebSocketWriter$FrameSink.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/cache/FaultHidingSink.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/http2/Http2Stream$FramingSink.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/cache2/Relay$RelaySource.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/Cache$CacheResponseBody$1.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$FixedLengthSource.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$UnknownLengthSource.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/http2/Http2Stream$FramingSource.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/http2/Http2Stream$StreamTimeout.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/http1/Http1Codec$ChunkedSink.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/http2/Http2Reader$ContinuationSource.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/Cache$CacheRequestImpl$1.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : okhttp3/internal/cache/CacheInterceptor$1.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : retrofit2/OkHttpCall$ExceptionCatchingRequestBody$1.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : org/apache/commons/logging/impl/ServletContextCleaner.class
[ERROR][10/11 08:55:40 PM]: Failed to load local script : com/thoughtworks/xstream/converters/reflection/CGLIBEnhancedConverter$ReverseEngineeredCallbackFilter.class

If i then try to run it regardless it throws me an uncaught exception

Spoiler

[ERROR][10/11 09:00:21 PM]: Uncaught exception!
java.lang.NoClassDefFoundError: okio/Sink
    at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:453)
    at ApiTest.onStart(ApiTest.java:23)
    at org.osbot.rs07.event.ScriptExecutor.iiiIIiiiiIIi(fo:194)
    at org.osbot.rs07.event.ScriptExecutor.start(fo:99)
    at org.osbot.Ib.run(uq:141)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: okio.Sink
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 8 more

 

So i must be doing something wrong, but not sure wat that might be, pretty sure mine looks the same likes yours for the rest

ps: this is currently just a siomple test script, that makes a call tot he github api, lines 23 is nothing but the BaseUrl that its suppose to connect with (

"https://api.github.com/"

)

 

@liverare

Trying your after i get back from the store (quickly before it closes) thanks in advance,

temp1.png

Edited by CrackplanetsCrac
Link to comment
Share on other sites

@liverare

I quickly tried it (couldn't help myself)

I got a folder on the dekstop called OsBot-api inthere a folder called lib and a bat file containing

java -cp "lib/*" org.osbot.Boot -debug

and then in the lib folder all the jar's including osbot

  image.png.c6ae039582a3e7e040a9121f6598ddcb.png

But whenever i run the command it throws and error at me
 

Error: Could not find or load main class org.osbot.Boot

Neither when i point it directly to my java install.

Link to comment
Share on other sites

42 minutes ago, CrackplanetsCrac said:

@liverare

I quickly tried it (couldn't help myself)

I got a folder on the dekstop called OsBot-api inthere a folder called lib and a bat file containing


java -cp "lib/*" org.osbot.Boot -debug

and then in the lib folder all the jar's including osbot

  image.png.c6ae039582a3e7e040a9121f6598ddcb.png

But whenever i run the command it throws and error at me
 


Error: Could not find or load main class org.osbot.Boot

Neither when i point it directly to my java install.

Why don’t you just use HttpURLConnection and if the response is JSON use Gson parser? A lot simple than all the dependencies 

Link to comment
Share on other sites

29 minutes ago, jca said:

Why don’t you just use HttpURLConnection and if the response is JSON use Gson parser? A lot simple than all the dependencies 

Just alot more experiance using these, but as it look now its gonna end up being the way that you are sugesting.
Just a shame, beccause this would also allow for more then just this, if i ever end up needing something else, then i still won't be able to do it, so kinda hoped i would find a working solution regardless.

Link to comment
Share on other sites

After some more testing i did get to start my client by doing wat @liverare suggested i did get my script to work, it nicely boots the osbot client, but once i then try and run a script that makes use of the library's i still get the errors

Spoiler

[ERROR][10/11 10:44:39 PM]: Uncaught exception!
java.lang.NoClassDefFoundError: okio/Sink

        at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:453)

        at ApiTest.onStart(ApiTest.java:23)

        at org.osbot.rs07.event.ScriptExecutor.iiiIIiiiiIIi(fo:194)

        at org.osbot.rs07.event.ScriptExecutor.start(fo:99)

        at org.osbot.Ib.run(uq:141)

        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

        at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.ClassNotFoundException: okio.Sink

        at java.net.URLClassLoader.findClass(Unknown Source)

        at java.lang.ClassLoader.loadClass(Unknown Source)

        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

        at java.lang.ClassLoader.loadClass(Unknown Source)

        ... 8 more

And alot more then i am willing to show (100's of lines of errors, basicly just one for every class)

Link to comment
Share on other sites

13 minutes ago, CrackplanetsCrac said:

Just alot more experiance using these, but as it look now its gonna end up being the way that you are sugesting.
Just a shame, beccause this would also allow for more then just this, if i ever end up needing something else, then i still won't be able to do it, so kinda hoped i would find a working solution regardless.

What more are you thinking? There’s always a solution! 

Link to comment
Share on other sites

55 minutes ago, jca said:

What more are you thinking? There’s always a solution! 

Rxjava, maybe jackson, or log4j.
I know that for alot of them there are default once, but those libraries are often easyer, quicker or just cleaner.
And i like to be able to just use them when ever.

Hell even doubtfull now if maven would even work.

Link to comment
Share on other sites

If I had to take a guess, the problem could either be:

  1. The batch file isn't loading all of the jar files in the /lib/ folder. I believe "lib/*" statement in the batch file would grab them all, but I could be wrong.
  2. The jar files aren't being included as dependencies when you compile your scripts.

I might take a look into this tomorrow.

Link to comment
Share on other sites

23 minutes ago, liverare said:

If I had to take a guess, the problem could either be:

  1. The batch file isn't loading all of the jar files in the /lib/ folder. I believe "lib/*" statement in the batch file would grab them all, but I could be wrong.
  2. The jar files aren't being included as dependencies when you compile your scripts.

I might take a look into this tomorrow.

Thanks for taking the time!
After some more testing i noticed that some kotlin files are needed that i did not include.
Trying to find out where to download those now, my issue with your way of doing it might not be the method, but rather me missing a jar in my lib.
I let you know once i know more.

Quick side note, any clue if this would work with maven projects? it would take alot of manual jars out of my hands.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...