Jump to content

External library support?


Recommended Posts

Posted

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

Posted

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
Posted
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?

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

Posted (edited)
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
Posted
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.

  • 2 months later...
Posted

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.

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

Posted

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.

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

  • 2 weeks later...
Posted

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.

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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