> For the complete documentation index, see [llms.txt](https://openjs.wiki.gd/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openjs.wiki.gd/openjs-components/using-java-in-scripts/javainscripts.md).

# 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

```js
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

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

***

{% hint style="warning" %}

#### Important Notes

* Make sure the `.jar` file is correctly placed inside the `Libs` folder 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 `importLib` only for trusted JARs to avoid security risks.
  {% endhint %}

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://openjs.wiki.gd/openjs-components/using-java-in-scripts/javainscripts.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
