Core changes
Generate Typescript definitions for Java classes in bulk
A new class, TypescriptBulkDefinitionGenerator
has been added in order to generate a lot of Typescript definitions for Java classes more easily:
import { TypescriptBulkDefinitionGenerator } from 'java-bridge';
const generator = new TypescriptBulkDefinitionGenerator();
// Generate definitions for the named classes
await generator.generate([
'java.io.FileOutputStream',
'java.io.FileInputStream',
'java.io.File',
'java.lang.System',
]);
// Retrieve the generated code
const definitions = generator.moduleDeclarations;
// Save the definitions to a directory
await generator.save('javaDefinitions');
Change the classpath at startup more easily
In order to make changing the classpath before starting the JVM more easy, two new options have been added to ensureJvm
:
classpath: string[]
- Single files or glob patterns to add to the classpathignoreUnreadableClassPathEntries: boolean
- Whether to ignore unreadable files in the classpath
With these new options, the classpath can be altered more easily, making sure some libraries like Spring Boot, which use a custom class loader can access all required dependencies at runtime, which is not guaranteed when using appendClasspath
.
import { ensureJvm } from 'java-bridge';
ensureJvm({
classpath: [
'/path/to/your/lib.jar',
// Glob patterns for adding directories are supported
'/path/to/a/directory/*',
// This also allows for adding only files of a specific type
'/path/to/files/*.jar',
],
// Don't throw an error if a file is unreadable
ignoreUnreadableClassPathEntries: true,
});
Additionally, ensureJvm
now returns a boolean
representing if the JVM has already been started by a previous call to java-bridge
.
It returns true
if the JVM has not already been started and this call to ensureJvm
was responsible for creating the JVM, if the call returns false
, the JVM has already been started by another call to java-bridge
and this call to ensureJvm
was basically a no-op.
import { ensureJvm } from 'java-bridge';
const started = ensureJvm();
if (!started) {
throw new Error('Failed to start the JVM as it is already running');
}
Glob patterns for appendClasspath
As with ensureJvm
, appendClasspath
now supports glob patterns to add directories more easily:
import { appendClasspath } from 'java-bridge';
// Import a directory recursively
appendClasspath('/path/to/files/**/*');
// Import multiple files at once
appendClasspath([
'/path/to/your/file.jar',
// Again, this allows for only adding files of a specific type
'/path/to/some/files/*.jar',
]);
This of course also works with classpath.append
:
import { classpath } from 'java-bridge';
// Import all jars inside directories recursively
classpath.append('/path/to/many/files/**/*.jar')
What's Changed
- fix(tsDefGen): add methods of superclasses to typescript definitions by @MarkusJx in #41
- fix(win32+arm64): fix win32 and arm64 build by @MarkusJx in #43
- feat(tsDefGen): add bulk typescript definition generator by @MarkusJx in #42
- feat(ci): add ci test reports by @MarkusJx in #45
- fix(classpath): IndexOutOfBounds when appending multiple files by @MarkusJx in #46
- feat(classpath): allow adding directories to the classpath by @MarkusJx in #47
- feat(startup): add convenience methods for altering the classpath by @MarkusJx in #49
Full Changelog: v2.1.7...v2.2.0