Load 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’s libs folder.

    • 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 riveScript

In 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


Last updated