Loading External JAR Libraries in Scripts
The importLib function allows your script to dynamically load and use external Java .jar libraries placed inside the plugin’s Libs folder.
This is useful for accessing additional Java classes or APIs not included by default in the server or plugin environment.
Syntax
var libLoader = importLib("library-name.jar");library-name.jar(String): The filename of the JAR library located inside the plugin’slibsfolder.The path is relative to the plugin’s directory, typically something like:
plugins/openjs/Libs/library-name.jar
How It Works
The library JAR is loaded at runtime, making all its public classes and resources available to your script.
After loading, you can use the returned loader object to get Java classes from the library, instantiate objects, and call methods.
This approach enables powerful extensibility by letting you integrate third-party Java libraries into your scripts.
Example Usage
var RiveScriptLoader = importLib("rivescript-core-0.9.2.jar");
var RiveScriptClass = RiveScriptLoader.loadClass("com.rivescript.RiveScript");
// Create an instance of the RiveScript bot
var riveScript = RiveScriptClass.getConstructor().newInstance();
// Now you can call methods on riveScriptIn this example, the RiveScript chatbot Java library is loaded from the Libs folder, and its main class is instantiated for use in your script.
Important Notes
Make sure the
.jarfile is correctly placed inside theLibsfolder of your plugin, and the filename matches exactly.The library must be compatible with the Java runtime your server uses.
Loading large libraries may impact startup or script execution time.
Use
importLibonly for trusted JARs to avoid security risks.
Last updated
Was this helpful?