Skip to content

Commit

Permalink
docs: Add section about extending the classpath (v2.0.1) (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusJx authored Aug 29, 2022
1 parent 8f02b4a commit db99e2e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,34 @@ ensureJvm({
});
```

### Inject a JAR into the class path

In order to import your own classes into the node environment, you need
to add the JAR file to the class path. You can do that with the
[`appendClasspath`](https://markusjx.github.io/node-java-bridge/functions/appendClasspath.html)
or [`classpath.append`](https://markusjx.github.io/node-java-bridge/functions/classpath.append.html)
methods. After loading a JAR, you can import classes from it like any other class
from the JVM using [`importClass`](#synchronous-calls) or [`importClassAsync`](#asynchronous-calls).

```ts
import { appendClasspath } from '@markusjx/java';

// Append a single jar to the class path
appendClasspath('/path/to/jar.jar');

// Append multiple jars to the class path
appendClasspath(['/path/to/jar1.jar', '/path/to/jar2.jar']);
```

or

```ts
import { classpath } from '@markusjx/java';

// Append a single jar to the class path
classpath.append('/path/to/jar.jar');
```

### Synchronous calls

If you want to use Java APIs in a synchronous way, you can use the synchronous API of this module.
Expand Down

0 comments on commit db99e2e

Please sign in to comment.