node-java-bridge icon indicating copy to clipboard operation
node-java-bridge copied to clipboard

Error "Unknown JNI version: 11". Support for Java >= 11

Open alberthastings opened this issue 1 year ago • 1 comments

My test

Used versions:

  • O.S.: Ubuntu 22.04.4 LTS
  • Node: v20.12.2
  • java-bridge: 2.6.0

Node script:

import javaBridge from 'java-bridge';
javaBridge.ensureJvm({
   classpath: [],
   ignoreUnreadableClassPathEntries: false,
   isPackagedElectron: false,   
   libPath: '/opt/jdk-11.0.21+9/lib/server/libjvm.so',   
   opts: [],   
   version: '11'
});
const System = javaBridge.importClass('java.lang.System');
System.out.println('Hello world!');

Execution result:

Error: Unknown JNI version: 11
   at Object.c (.../node_modules/java-bridge/dist/index.prod.min.js:1:9102)
   at .../src/main.js:3:12
   at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
   at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
   at async loadESM (node:internal/process/esm_loader:28:7)
   at async handleMainPromise (node:internal/modules/run_main:113:12) {code: 'GenericFailure'}

Note: Tested with

libPath: '/opt/jdk1.8.0_131/jre/lib/amd64/server/libjvm.so',   
version: javaBridge.JavaVersion.VER_8

gives sucessfull result.

My request

According to

, "java-bridge" only supports these Java versions: 1.1, 1.2, 1.4, 1.6, 1.8, 9, and 10.

Could you implement support for Java >= 11?

alberthastings avatar Aug 14 '24 09:08 alberthastings

As far as I know, this parameter only sets the JNI version to be used, not the JVM version being used. The JVM version used depends on the JRE you are running this package with.

For older JNI versions, 10 is actually the highest one available, enabling support for JNI 10 or higher. Starting from Java 19, they've added three new JNI versions, those being 19, 20 and 21, so I may add those in the future, although I'm not really seeing a benefit to doing this as it won't affect the JVM version being used. I'll definitely have to update the documentation regarding this option, since the current documentation isn't quite accurate.

MarkusJx avatar Aug 14 '24 19:08 MarkusJx