Jump to content

External library support?


Ruinedscape

Recommended Posts

Hi, started writing scripts and decided it would be a good idea to put common functions into their own project and import the packages into the scripts I write.

The code compiles fine but when run I get java.lang.ClassNotFoundException and java.lang.NoClassDefFoundError exceptions.

From a quick search of the forum it seems other people have had similar issues with external libraries but can't see any fixes.

 

Is it possible to use an external library (that you create and have the source for) in your osbot scripts?

 

Cheers

Link to comment
Share on other sites

The following post is for eclipse

 

Untested, but here's an idea. (seriously not sure if it'll work, never done it before)

 

When you get ready to export and what all them libraries to go with your script jar, open them in the project window and Export..Jar file

On the export (not as runnable jar) screen in eclipse tick the checkbox for each of the projects which is a library (given you have the source code). You'll probably have to change your dependencies from external jars to include those projects for your api(s)

eea25661ec.png

  • Like 1
Link to comment
Share on other sites

7 minutes ago, Polymorphism said:

The following post is for eclipse

 

Untested, but here's an idea. (seriously not sure if it'll work, never done it before)

 

When you get ready to export and what all them libraries to go with your script jar, open them in the project window and Export..Jar file

On the export (not as runnable jar) screen in eclipse tick the checkbox for each of the projects which is a library (given you have the source code). You'll probably have to change your dependencies from external jars to include those projects for your api(s)

eea25661ec.png

I'm using intellij and can't find options similar to this. Any ideas?

Link to comment
Share on other sites

13 minutes ago, Polymorphism said:

They don't apply but thanks for your help man.

Shall try again tomorrow. There's got to be people using their own libraries of code and not just copy pasting functions and classes into every script... hopefully they'll see this.

  • Like 1
Link to comment
Share on other sites

34 minutes ago, Ruinedscape said:

They don't apply but thanks for your help man.

Shall try again tomorrow. There's got to be people using their own libraries of code and not just copy pasting functions and classes into every script... hopefully they'll see this.

No problem, I have been thinking the same thing honestly. Gonna follow to see if someone has a viable answer.

Link to comment
Share on other sites

36 minutes ago, Abuse said:

It's easy to do this in intelliJ:

Open the module settings and add your library (May it be a .jar or source folder)

 

 

Then go to artifacts and add your freshly added library to the build output

 

And you're done :)

 

 

This seems like the intellij equivalent of what I posted. Although I'm not sure if what I posted would work, never tried it with source files. Just know of it from experience

Edited by Polymorphism
removed quoted images
Link to comment
Share on other sites

9 hours ago, Abuse said:

It's easy to do this in intelliJ:

Open the module settings and add your library (May it be a .jar or source folder)

tfVdew6.png

 

Then go to artifacts and add your freshly added library to the build output

LhdhLup.png

And you're done :)

Ahh you hero. I had the library in the jar, not the compiled output as I didn't add it as a module. Thanks.

Link to comment
Share on other sites

  • 2 months later...

You don't need to make Jar's. OSBot's classloader fails a bit on picking up on scripts that are compiled from separate modules (especially if you're using a custom API that is used by all scripts). To work around this problem you can either compile everything in a Jar OR don't use separate modules (looks ugly works perfectly) OR change how Intellij compiles your modules. If you make sure that every module has a custom compiling destination set to the OSBot/Scripts folder (including your API/dependencies) it should work fine.

Link to comment
Share on other sites

5 hours ago, Krulvis said:

You don't need to make Jar's. OSBot's classloader fails a bit on picking up on scripts that are compiled from separate modules (especially if you're using a custom API that is used by all scripts). To work around this problem you can either compile everything in a Jar OR don't use separate modules (looks ugly works perfectly) OR change how Intellij compiles your modules. If you make sure that every module has a custom compiling destination set to the OSBot/Scripts folder (including your API/dependencies) it should work fine.

 

You misunderstood the problem, through the normal script loader it is not possible to use scripts that call external libs... you have to rebuild the OSBot jar to include the external libs in order to get those scripts to work.

Link to comment
Share on other sites

You need to extract the contents from your Jar folder to your Script folder.

 

Do so like you would a zip folder.

 

If your using your Script folder as an output folder in your IDE, then your IDE will clean out that folder each time your code is recompiled, which happens each time you save. If this is the case, you'll want to extract the contents of the Jar to your project's source folder so that it'll be outputted each time automatically and you won't have to re-extract stuff over and over again.

Link to comment
Share on other sites

On 9-4-2017 at 3:03 AM, Trees said:

 

You misunderstood the problem, through the normal script loader it is not possible to use scripts that call external libs... you have to rebuild the OSBot jar to include the external libs in order to get those scripts to work.

 

On 9-4-2017 at 11:25 AM, liverare said:

You need to extract the contents from your Jar folder to your Script folder.

 

Do so like you would a zip folder.

 

If your using your Script folder as an output folder in your IDE, then your IDE will clean out that folder each time your code is recompiled, which happens each time you save. If this is the case, you'll want to extract the contents of the Jar to your project's source folder so that it'll be outputted each time automatically and you won't have to re-extract stuff over and over again.

The OP stated that it is about an external library that he has the source for. In this case you can just have it build from a separate module in the same project. I was assuming it's about an separate API or GSON lib. This is what I use as well, and works just fine the way I described it.

Link to comment
Share on other sites

  • 2 weeks later...

I use IntelliJ IDEA and every time you add a library after initially configuring the artefact, you need to go into the artefact settings, press plus and selected "Extracted Directory" (something to that effect), and then select the libraries jar file(s).

Bare in mind though that OSBot's SecurityManager blocks certain permissions, meaning things like Commons HTTP won't be able to load as they depend on a system proxy detection which is blocked for some reason.

 

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...