Ruinedscape Posted February 5, 2017 Share Posted February 5, 2017 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 Quote Link to comment Share on other sites More sharing options...
Polymorphism Posted February 5, 2017 Share Posted February 5, 2017 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) 1 Quote Link to comment Share on other sites More sharing options...
Ruinedscape Posted February 5, 2017 Author Share Posted February 5, 2017 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) I'm using intellij and can't find options similar to this. Any ideas? Quote Link to comment Share on other sites More sharing options...
Polymorphism Posted February 5, 2017 Share Posted February 5, 2017 I don't use Intellij very much, so I'm not 100% sure but give them links a read and try https://www.jetbrains.com/help/idea/2016.3/configuring-module-dependencies-and-libraries.html#add_module_dependency https://blog.jetbrains.com/idea/2010/08/quickly-create-jar-artifact/ 1 Quote Link to comment Share on other sites More sharing options...
Ruinedscape Posted February 5, 2017 Author Share Posted February 5, 2017 13 minutes ago, Polymorphism said: I don't use Intellij very much, so I'm not 100% sure but give them links a read and try https://www.jetbrains.com/help/idea/2016.3/configuring-module-dependencies-and-libraries.html#add_module_dependency https://blog.jetbrains.com/idea/2010/08/quickly-create-jar-artifact/ 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. 1 Quote Link to comment Share on other sites More sharing options...
Polymorphism Posted February 5, 2017 Share Posted February 5, 2017 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. Quote Link to comment Share on other sites More sharing options...
Abuse Posted February 5, 2017 Share Posted February 5, 2017 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 2 Quote Link to comment Share on other sites More sharing options...
Polymorphism Posted February 5, 2017 Share Posted February 5, 2017 (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 February 5, 2017 by Polymorphism removed quoted images Quote Link to comment Share on other sites More sharing options...
Ruinedscape Posted February 5, 2017 Author Share Posted February 5, 2017 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) Then go to artifacts and add your freshly added library to the build output 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. Quote Link to comment Share on other sites More sharing options...
Krulvis Posted April 8, 2017 Share Posted April 8, 2017 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. Quote Link to comment Share on other sites More sharing options...
Trees Posted April 9, 2017 Share Posted April 9, 2017 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. Quote Link to comment Share on other sites More sharing options...
liverare Posted April 9, 2017 Share Posted April 9, 2017 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. Quote Link to comment Share on other sites More sharing options...
Krulvis Posted April 14, 2017 Share Posted April 14, 2017 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. Quote Link to comment Share on other sites More sharing options...
dmms659 Posted April 24, 2017 Share Posted April 24, 2017 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. Quote Link to comment Share on other sites More sharing options...