java-bridge
Advanced tools
Comparing version 2.5.2 to 2.6.0
@@ -270,1 +270,43 @@ /// <reference types="node" /> | ||
} | ||
/** | ||
* An error thrown from the java process. | ||
* This error may contain the java throwable | ||
* that caused this error. The cause is only | ||
* available in synchronous calls. | ||
*/ | ||
export declare class JavaError extends Error { | ||
/** | ||
* The throwable that caused this error. | ||
* This is only available in synchronous calls or | ||
* if the {@link JavaConfig.asyncJavaExceptionObjects} option is true. | ||
*/ | ||
readonly cause?: JavaThrowable; | ||
} | ||
/** | ||
* A definition for the java throwable class. | ||
* @see https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html | ||
*/ | ||
export declare class JavaThrowable extends UnknownJavaClass { | ||
addSuppressedSync(suppressed: JavaThrowable): void; | ||
addSuppressed(suppressed: JavaThrowable): Promise<void>; | ||
fillInStackTraceSync(): void; | ||
fillInStackTrace(): Promise<void>; | ||
getCauseSync(): JavaThrowable; | ||
getCause(): Promise<JavaThrowable>; | ||
getMessageSync(): string; | ||
getMessage(): Promise<string>; | ||
getLocalizedMessageSync(): string; | ||
getLocalizedMessage(): Promise<string>; | ||
getStackTraceSync(): UnknownJavaClass[]; | ||
getStackTrace(): Promise<UnknownJavaClass[]>; | ||
getSuppressedSync(): JavaThrowable[]; | ||
getSuppressed(): Promise<JavaThrowable[]>; | ||
initCauseSync(cause: JavaThrowable): JavaThrowable; | ||
initCause(cause: JavaThrowable): Promise<JavaThrowable>; | ||
printStackTraceSync(): void; | ||
printStackTrace(): Promise<void>; | ||
printStackTraceSync(out: JavaObject): void; | ||
printStackTrace(out: JavaObject): Promise<void>; | ||
setStackTraceSync(stackTrace: UnknownJavaClass[]): void; | ||
setStackTrace(stackTrace: UnknownJavaClass[]): Promise<void>; | ||
} |
@@ -1,2 +0,2 @@ | ||
export { JavaVersion, JavaObject, JavaClassInstance, JavaClassProxy, JavaClass, JavaClassConstructor, UnknownJavaClass, JavaType, BasicOrJavaType, BasicType, JavaClassType, Constructor, UnknownJavaClassType, JavaClassConstructorType, } from './definitions'; | ||
export { JavaVersion, JavaObject, JavaClassInstance, JavaClassProxy, JavaClass, JavaClassConstructor, UnknownJavaClass, JavaType, BasicOrJavaType, BasicType, JavaClassType, Constructor, UnknownJavaClassType, JavaClassConstructorType, JavaError, JavaThrowable, } from './definitions'; | ||
import type * as internal from '../native'; | ||
@@ -3,0 +3,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.java=r():e.java=r()}(global,(()=>(()=>{var e={309:(e,r,a)=>{e=a.nmd(e);try{process.dlopen(e,__dirname+a(928).sep+a.p+"java.linux-x64-gnu.node")}catch(e){throw new Error("node-loader:\n"+e)}},147:(e,r,a)=>{const{existsSync:n,readFileSync:t}=a(896),{join:o}=a(928),{platform:i,arch:c}=process;let s=null,u=!1,d=null;function l(){if(process.report&&"function"==typeof process.report.getReport){const{glibcVersionRuntime:e}=process.report.getReport().header;return!e}try{const e=a(317).execSync("which ldd").toString().trim();return t(e,"utf8").includes("musl")}catch(e){return!0}}switch(i){case"android":switch(c){case"arm64":u=n(o(__dirname,"java.android-arm64.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.android-arm64.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-android-arm64")}catch(e){d=e}break;case"arm":u=n(o(__dirname,"java.android-arm-eabi.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.android-arm-eabi.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-android-arm-eabi")}catch(e){d=e}break;default:throw new Error(`Unsupported architecture on Android ${c}`)}break;case"win32":switch(c){case"x64":u=n(o(__dirname,"java.win32-x64-msvc.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.win32-x64-msvc.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-win32-x64-msvc")}catch(e){d=e}break;case"ia32":u=n(o(__dirname,"java.win32-ia32-msvc.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.win32-ia32-msvc.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-win32-ia32-msvc")}catch(e){d=e}break;case"arm64":u=n(o(__dirname,"java.win32-arm64-msvc.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.win32-arm64-msvc.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-win32-arm64-msvc")}catch(e){d=e}break;default:throw new Error(`Unsupported architecture on Windows: ${c}`)}break;case"darwin":u=n(o(__dirname,"java.darwin-universal.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.darwin-universal.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-darwin-universal");break}catch{}switch(c){case"x64":u=n(o(__dirname,"java.darwin-x64.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.darwin-x64.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-darwin-x64")}catch(e){d=e}break;case"arm64":u=n(o(__dirname,"java.darwin-arm64.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.darwin-arm64.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-darwin-arm64")}catch(e){d=e}break;default:throw new Error(`Unsupported architecture on macOS: ${c}`)}break;case"freebsd":if("x64"!==c)throw new Error(`Unsupported architecture on FreeBSD: ${c}`);u=n(o(__dirname,"java.freebsd-x64.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.freebsd-x64.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-freebsd-x64")}catch(e){d=e}break;case"linux":switch(c){case"x64":if(l()){u=n(o(__dirname,"java.linux-x64-musl.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.linux-x64-musl.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-linux-x64-musl")}catch(e){d=e}}else{u=n(o(__dirname,"java.linux-x64-gnu.node"));try{s=u?a(309):require("java-bridge-linux-x64-gnu")}catch(e){d=e}}break;case"arm64":if(l()){u=n(o(__dirname,"java.linux-arm64-musl.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.linux-arm64-musl.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-linux-arm64-musl")}catch(e){d=e}}else{u=n(o(__dirname,"java.linux-arm64-gnu.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.linux-arm64-gnu.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-linux-arm64-gnu")}catch(e){d=e}}break;case"arm":u=n(o(__dirname,"java.linux-arm-gnueabihf.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.linux-arm-gnueabihf.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-linux-arm-gnueabihf")}catch(e){d=e}break;case"riscv64":if(l()){u=n(o(__dirname,"java.linux-riscv64-musl.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.linux-riscv64-musl.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-linux-riscv64-musl")}catch(e){d=e}}else{u=n(o(__dirname,"java.linux-riscv64-gnu.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.linux-riscv64-gnu.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-linux-riscv64-gnu")}catch(e){d=e}}break;case"s390x":u=n(o(__dirname,"java.linux-s390x-gnu.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.linux-s390x-gnu.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-linux-s390x-gnu")}catch(e){d=e}break;default:throw new Error(`Unsupported architecture on Linux: ${c}`)}break;default:throw new Error(`Unsupported OS: ${i}, architecture: ${c}`)}if(!s){if(d)throw d;throw new Error("Failed to load native binding")}const{JavaInterfaceProxy:v,clearDaemonProxies:f,Java:b,clearClassProxies:p,JavaConfig:m,StdoutRedirect:j,getJavaLibPath:g,logging:_}=s;e.exports.JavaInterfaceProxy=v,e.exports.clearDaemonProxies=f,e.exports.Java=b,e.exports.clearClassProxies=p,e.exports.JavaConfig=m,e.exports.StdoutRedirect=j,e.exports.getJavaLibPath=g,e.exports.logging=_},514:(e,r,a)=>{"use strict";var n;Object.defineProperty(r,"__esModule",{value:!0}),r.JavaObject=r.JavaVersion=void 0,a(23),function(e){e.VER_1_1="1.1",e.VER_1_2="1.2",e.VER_1_4="1.4",e.VER_1_6="1.6",e.VER_1_8="1.8",e.VER_9="9",e.VER_10="10"}(n||(r.JavaVersion=n={})),Object.freeze(n),r.JavaObject=class{}},772:function(e,r,a){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,r,a,n){void 0===n&&(n=a);var t=Object.getOwnPropertyDescriptor(r,a);t&&!("get"in t?!r.__esModule:t.writable||t.configurable)||(t={enumerable:!0,get:function(){return r[a]}}),Object.defineProperty(e,n,t)}:function(e,r,a,n){void 0===n&&(n=a),e[n]=r[a]}),t=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),o=this&&this.__exportStar||function(e,r){for(var a in e)"default"===a||Object.prototype.hasOwnProperty.call(r,a)||n(r,e,a)},i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&n(r,e,a);return t(r,e),r};Object.defineProperty(r,"__esModule",{value:!0}),r.getJavaVersionSync=r.getJavaVersion=r.getJavaLibPath=r.UnknownJavaClass=r.JavaClassConstructor=r.JavaClass=r.JavaClassProxy=r.JavaClassInstance=r.JavaObject=r.JavaVersion=void 0;var c=a(514);Object.defineProperty(r,"JavaVersion",{enumerable:!0,get:function(){return c.JavaVersion}}),Object.defineProperty(r,"JavaObject",{enumerable:!0,get:function(){return c.JavaObject}}),Object.defineProperty(r,"JavaClassInstance",{enumerable:!0,get:function(){return c.JavaClassInstance}}),Object.defineProperty(r,"JavaClassProxy",{enumerable:!0,get:function(){return c.JavaClassProxy}}),Object.defineProperty(r,"JavaClass",{enumerable:!0,get:function(){return c.JavaClass}}),Object.defineProperty(r,"JavaClassConstructor",{enumerable:!0,get:function(){return c.JavaClassConstructor}}),Object.defineProperty(r,"UnknownJavaClass",{enumerable:!0,get:function(){return c.UnknownJavaClass}}),o(a(230),r);const s=i(a(230));r.default=s;var u=a(147);Object.defineProperty(r,"getJavaLibPath",{enumerable:!0,get:function(){return u.getJavaLibPath}});var d=a(242);Object.defineProperty(r,"getJavaVersion",{enumerable:!0,get:function(){return d.getJavaVersion}}),Object.defineProperty(r,"getJavaVersionSync",{enumerable:!0,get:function(){return d.getJavaVersionSync}})},230:(e,r,a)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.config=r.getJavaInstance=r.newProxy=r.stdout=r.classpath=r.isInstanceOf=r.deleteObject=r.appendClasspath=r.importClassAsync=r.importClass=r.setClassLoader=r.getClassLoader=r.ensureJvm=r.logging=r.clearClassProxies=r.clearDaemonProxies=void 0;const n=a(147),t=a(74);var o=a(147);Object.defineProperty(r,"clearDaemonProxies",{enumerable:!0,get:function(){return o.clearDaemonProxies}}),Object.defineProperty(r,"clearClassProxies",{enumerable:!0,get:function(){return o.clearClassProxies}}),Object.defineProperty(r,"logging",{enumerable:!0,get:function(){return o.logging}});let i=null;function c(e){return!i&&(i=new n.Java(e?.libPath,e?.version,e?.opts,e,(0,t.getJavaLibPath)(),(0,t.getNativeLibPath)(e?.isPackagedElectron??!1)),!0)}function s(e){c(),i.appendClasspath(e)}var u,d;r.ensureJvm=c,r.getClassLoader=function(){return c(),i.classLoader},r.setClassLoader=function(e){c(),i.classLoader=e},r.importClass=function(e,r){return c(),i.importClass(e,r)},r.importClassAsync=function(e,r){return c(),i.importClassAsync(e,r)},r.appendClasspath=s,r.deleteObject=function(e){c(),i.delete(e)},r.isInstanceOf=function(e,r){return c(),i.isInstanceOf(e,r)},function(e){e.append=function(e){s(e)},e.get=function(){return c(),i.loadedJars}}(u||(r.classpath=u={})),(d||(r.stdout=d={})).enableRedirect=function(e,r){return c(),i.setStdoutCallbacks(e,r)},r.newProxy=function(e,r,a){c();const n=Object.create(null);for(const[e,a]of Object.entries(r))n[e]=(e,r,...n)=>{if(e)throw e;try{const e=a(...n);e instanceof Promise?e.then((e=>r(null,e)),(e=>{e instanceof Error?r(e):r(new Error(String(e)))})):r(null,e)}catch(e){e instanceof Error?r(e):r(new Error(String(e)))}};return i.createInterfaceProxy(e,n,a)},r.getJavaInstance=function(){return i},r.config=new n.JavaConfig},74:function(e,r,a){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,r,a,n){void 0===n&&(n=a);var t=Object.getOwnPropertyDescriptor(r,a);t&&!("get"in t?!r.__esModule:t.writable||t.configurable)||(t={enumerable:!0,get:function(){return r[a]}}),Object.defineProperty(e,n,t)}:function(e,r,a,n){void 0===n&&(n=a),e[n]=r[a]}),t=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&n(r,e,a);return t(r,e),r},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0}),r.getJavaLibPath=r.getNativeLibPath=void 0;const c=i(a(928)),s=o(a(896)),{platform:u,arch:d}=process,l=/([\\/])app\.asar([\\/])/gim;function v(e,r){const n=c.default.join(__dirname,e+".node");if(s.default.existsSync(n))return r&&console.warn("Using local native module in packaged Electron app"),n;{const n=e.replaceAll(".","-").replace("java","java-bridge");let t;return t=require&&require.resolve?require.resolve(n):a(973).resolve(n),r&&(t=t.replace(l,"$1app.asar.unpacked$2")),t}}function f(){return new Error(`Unsupported platform: ${u} ${d}`)}r.getNativeLibPath=function(e){switch(u){case"android":switch(d){case"arm64":return v("java.android-arm64",e);case"arm":return v("java.android-arm-eabi",e);default:throw f()}case"win32":return v(`java.win32-${d}-msvc`,e);case"darwin":return v(`java.darwin-${d}`,e);case"freebsd":return v(`java.freebsd-${d}`,e);case"linux":switch(d){case"x64":case"arm64":return v(`java.linux-${d}-${function(){if(process.report&&"function"==typeof process.report.getReport){const{glibcVersionRuntime:e}=process.report.getReport().header;return!e}try{return(0,s.readFileSync)("/usr/bin/ldd","utf8").includes("musl")}catch(e){return!0}}()?"musl":"gnu"}`,e);case"arm":return v("java.linux-arm-gnueabihf",e);default:throw f()}default:throw f()}},r.getJavaLibPath=function(){const e=c.default.join(__dirname,"JavaBridge.jar");if(s.default.existsSync(e)&&s.default.statSync(e).isFile())return e;throw new Error("JavaBridge.jar not found")}},242:(e,r,a)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.getJavaVersionSync=r.getJavaVersion=void 0;const n=a(230);r.getJavaVersion=async function(){const e=await(0,n.importClassAsync)("java.lang.System");return await e.getProperty("java.version")},r.getJavaVersionSync=function(){return(0,n.importClass)("java.lang.System").getPropertySync("java.version")}},973:e=>{function r(e){var r=new Error("Cannot find module '"+e+"'");throw r.code="MODULE_NOT_FOUND",r}r.keys=()=>[],r.resolve=r,r.id=973,e.exports=r},317:e=>{"use strict";e.exports=require("child_process")},896:e=>{"use strict";e.exports=require("fs")},928:e=>{"use strict";e.exports=require("path")},23:e=>{"use strict";e.exports=require("util")}},r={};function a(n){var t=r[n];if(void 0!==t)return t.exports;var o=r[n]={id:n,loaded:!1,exports:{}};return e[n].call(o.exports,o,o.exports,a),o.loaded=!0,o.exports}return a.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),a.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),a.p="",a(772)})())); | ||
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.java=r():e.java=r()}(global,(()=>(()=>{var e={309:(e,r,a)=>{e=a.nmd(e);try{process.dlopen(e,__dirname+a(928).sep+a.p+"java.linux-x64-gnu.node")}catch(e){throw new Error("node-loader:\n"+e)}},147:(e,r,a)=>{const{existsSync:n,readFileSync:t}=a(896),{join:o}=a(928),{platform:i,arch:c}=process;let s=null,u=!1,d=null;function l(){if(process.report&&"function"==typeof process.report.getReport){const{glibcVersionRuntime:e}=process.report.getReport().header;return!e}try{const e=a(317).execSync("which ldd").toString().trim();return t(e,"utf8").includes("musl")}catch(e){return!0}}switch(i){case"android":switch(c){case"arm64":u=n(o(__dirname,"java.android-arm64.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.android-arm64.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-android-arm64")}catch(e){d=e}break;case"arm":u=n(o(__dirname,"java.android-arm-eabi.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.android-arm-eabi.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-android-arm-eabi")}catch(e){d=e}break;default:throw new Error(`Unsupported architecture on Android ${c}`)}break;case"win32":switch(c){case"x64":u=n(o(__dirname,"java.win32-x64-msvc.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.win32-x64-msvc.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-win32-x64-msvc")}catch(e){d=e}break;case"ia32":u=n(o(__dirname,"java.win32-ia32-msvc.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.win32-ia32-msvc.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-win32-ia32-msvc")}catch(e){d=e}break;case"arm64":u=n(o(__dirname,"java.win32-arm64-msvc.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.win32-arm64-msvc.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-win32-arm64-msvc")}catch(e){d=e}break;default:throw new Error(`Unsupported architecture on Windows: ${c}`)}break;case"darwin":u=n(o(__dirname,"java.darwin-universal.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.darwin-universal.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-darwin-universal");break}catch{}switch(c){case"x64":u=n(o(__dirname,"java.darwin-x64.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.darwin-x64.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-darwin-x64")}catch(e){d=e}break;case"arm64":u=n(o(__dirname,"java.darwin-arm64.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.darwin-arm64.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-darwin-arm64")}catch(e){d=e}break;default:throw new Error(`Unsupported architecture on macOS: ${c}`)}break;case"freebsd":if("x64"!==c)throw new Error(`Unsupported architecture on FreeBSD: ${c}`);u=n(o(__dirname,"java.freebsd-x64.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.freebsd-x64.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-freebsd-x64")}catch(e){d=e}break;case"linux":switch(c){case"x64":if(l()){u=n(o(__dirname,"java.linux-x64-musl.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.linux-x64-musl.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-linux-x64-musl")}catch(e){d=e}}else{u=n(o(__dirname,"java.linux-x64-gnu.node"));try{s=u?a(309):require("java-bridge-linux-x64-gnu")}catch(e){d=e}}break;case"arm64":if(l()){u=n(o(__dirname,"java.linux-arm64-musl.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.linux-arm64-musl.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-linux-arm64-musl")}catch(e){d=e}}else{u=n(o(__dirname,"java.linux-arm64-gnu.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.linux-arm64-gnu.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-linux-arm64-gnu")}catch(e){d=e}}break;case"arm":u=n(o(__dirname,"java.linux-arm-gnueabihf.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.linux-arm-gnueabihf.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-linux-arm-gnueabihf")}catch(e){d=e}break;case"riscv64":if(l()){u=n(o(__dirname,"java.linux-riscv64-musl.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.linux-riscv64-musl.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-linux-riscv64-musl")}catch(e){d=e}}else{u=n(o(__dirname,"java.linux-riscv64-gnu.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.linux-riscv64-gnu.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-linux-riscv64-gnu")}catch(e){d=e}}break;case"s390x":u=n(o(__dirname,"java.linux-s390x-gnu.node"));try{s=u?a(Object(function(){var e=new Error("Cannot find module './java.linux-s390x-gnu.node'");throw e.code="MODULE_NOT_FOUND",e}())):require("java-bridge-linux-s390x-gnu")}catch(e){d=e}break;default:throw new Error(`Unsupported architecture on Linux: ${c}`)}break;default:throw new Error(`Unsupported OS: ${i}, architecture: ${c}`)}if(!s){if(d)throw d;throw new Error("Failed to load native binding")}const{JavaInterfaceProxy:v,clearDaemonProxies:f,Java:b,clearClassProxies:p,JavaConfig:m,StdoutRedirect:j,getJavaLibPath:g,logging:_}=s;e.exports.JavaInterfaceProxy=v,e.exports.clearDaemonProxies=f,e.exports.Java=b,e.exports.clearClassProxies=p,e.exports.JavaConfig=m,e.exports.StdoutRedirect=j,e.exports.getJavaLibPath=g,e.exports.logging=_},514:(e,r,a)=>{"use strict";var n;Object.defineProperty(r,"__esModule",{value:!0}),r.JavaObject=r.JavaVersion=void 0,a(23),function(e){e.VER_1_1="1.1",e.VER_1_2="1.2",e.VER_1_4="1.4",e.VER_1_6="1.6",e.VER_1_8="1.8",e.VER_9="9",e.VER_10="10"}(n||(r.JavaVersion=n={})),Object.freeze(n),r.JavaObject=class{}},772:function(e,r,a){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,r,a,n){void 0===n&&(n=a);var t=Object.getOwnPropertyDescriptor(r,a);t&&!("get"in t?!r.__esModule:t.writable||t.configurable)||(t={enumerable:!0,get:function(){return r[a]}}),Object.defineProperty(e,n,t)}:function(e,r,a,n){void 0===n&&(n=a),e[n]=r[a]}),t=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),o=this&&this.__exportStar||function(e,r){for(var a in e)"default"===a||Object.prototype.hasOwnProperty.call(r,a)||n(r,e,a)},i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&n(r,e,a);return t(r,e),r};Object.defineProperty(r,"__esModule",{value:!0}),r.getJavaVersionSync=r.getJavaVersion=r.getJavaLibPath=r.JavaThrowable=r.JavaError=r.UnknownJavaClass=r.JavaClassConstructor=r.JavaClass=r.JavaClassProxy=r.JavaClassInstance=r.JavaObject=r.JavaVersion=void 0;var c=a(514);Object.defineProperty(r,"JavaVersion",{enumerable:!0,get:function(){return c.JavaVersion}}),Object.defineProperty(r,"JavaObject",{enumerable:!0,get:function(){return c.JavaObject}}),Object.defineProperty(r,"JavaClassInstance",{enumerable:!0,get:function(){return c.JavaClassInstance}}),Object.defineProperty(r,"JavaClassProxy",{enumerable:!0,get:function(){return c.JavaClassProxy}}),Object.defineProperty(r,"JavaClass",{enumerable:!0,get:function(){return c.JavaClass}}),Object.defineProperty(r,"JavaClassConstructor",{enumerable:!0,get:function(){return c.JavaClassConstructor}}),Object.defineProperty(r,"UnknownJavaClass",{enumerable:!0,get:function(){return c.UnknownJavaClass}}),Object.defineProperty(r,"JavaError",{enumerable:!0,get:function(){return c.JavaError}}),Object.defineProperty(r,"JavaThrowable",{enumerable:!0,get:function(){return c.JavaThrowable}}),o(a(230),r);const s=i(a(230));r.default=s;var u=a(147);Object.defineProperty(r,"getJavaLibPath",{enumerable:!0,get:function(){return u.getJavaLibPath}});var d=a(242);Object.defineProperty(r,"getJavaVersion",{enumerable:!0,get:function(){return d.getJavaVersion}}),Object.defineProperty(r,"getJavaVersionSync",{enumerable:!0,get:function(){return d.getJavaVersionSync}})},230:(e,r,a)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.config=r.getJavaInstance=r.newProxy=r.stdout=r.classpath=r.isInstanceOf=r.deleteObject=r.appendClasspath=r.importClassAsync=r.importClass=r.setClassLoader=r.getClassLoader=r.ensureJvm=r.logging=r.clearClassProxies=r.clearDaemonProxies=void 0;const n=a(147),t=a(74);var o=a(147);Object.defineProperty(r,"clearDaemonProxies",{enumerable:!0,get:function(){return o.clearDaemonProxies}}),Object.defineProperty(r,"clearClassProxies",{enumerable:!0,get:function(){return o.clearClassProxies}}),Object.defineProperty(r,"logging",{enumerable:!0,get:function(){return o.logging}});let i=null;function c(e){return!i&&(i=new n.Java(e?.libPath,e?.version,e?.opts,e,(0,t.getJavaLibPath)(),(0,t.getNativeLibPath)(e?.isPackagedElectron??!1)),!0)}function s(e){c(),i.appendClasspath(e)}var u,d;r.ensureJvm=c,r.getClassLoader=function(){return c(),i.classLoader},r.setClassLoader=function(e){c(),i.classLoader=e},r.importClass=function(e,r){return c(),i.importClass(e,r)},r.importClassAsync=function(e,r){return c(),i.importClassAsync(e,r)},r.appendClasspath=s,r.deleteObject=function(e){c(),i.delete(e)},r.isInstanceOf=function(e,r){return c(),i.isInstanceOf(e,r)},function(e){e.append=function(e){s(e)},e.get=function(){return c(),i.loadedJars}}(u||(r.classpath=u={})),(d||(r.stdout=d={})).enableRedirect=function(e,r){return c(),i.setStdoutCallbacks(e,r)},r.newProxy=function(e,r,a){c();const n=Object.create(null);for(const[e,a]of Object.entries(r))n[e]=(e,r,...n)=>{if(e)throw e;try{const e=a(...n);e instanceof Promise?e.then((e=>r(null,e)),(e=>{e instanceof Error?r(e):r(new Error(String(e)))})):r(null,e)}catch(e){e instanceof Error?r(e):r(new Error(String(e)))}};return i.createInterfaceProxy(e,n,a)},r.getJavaInstance=function(){return i},r.config=new n.JavaConfig},74:function(e,r,a){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,r,a,n){void 0===n&&(n=a);var t=Object.getOwnPropertyDescriptor(r,a);t&&!("get"in t?!r.__esModule:t.writable||t.configurable)||(t={enumerable:!0,get:function(){return r[a]}}),Object.defineProperty(e,n,t)}:function(e,r,a,n){void 0===n&&(n=a),e[n]=r[a]}),t=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&n(r,e,a);return t(r,e),r},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0}),r.getJavaLibPath=r.getNativeLibPath=void 0;const c=i(a(928)),s=o(a(896)),{platform:u,arch:d}=process,l=/([\\/])app\.asar([\\/])/gim;function v(e,r){const n=c.default.join(__dirname,e+".node");if(s.default.existsSync(n))return r&&console.warn("Using local native module in packaged Electron app"),n;{const n=e.replaceAll(".","-").replace("java","java-bridge");let t;return t=require&&require.resolve?require.resolve(n):a(973).resolve(n),r&&(t=t.replace(l,"$1app.asar.unpacked$2")),t}}function f(){return new Error(`Unsupported platform: ${u} ${d}`)}r.getNativeLibPath=function(e){switch(u){case"android":switch(d){case"arm64":return v("java.android-arm64",e);case"arm":return v("java.android-arm-eabi",e);default:throw f()}case"win32":return v(`java.win32-${d}-msvc`,e);case"darwin":return v(`java.darwin-${d}`,e);case"freebsd":return v(`java.freebsd-${d}`,e);case"linux":switch(d){case"x64":case"arm64":return v(`java.linux-${d}-${function(){if(process.report&&"function"==typeof process.report.getReport){const{glibcVersionRuntime:e}=process.report.getReport().header;return!e}try{return(0,s.readFileSync)("/usr/bin/ldd","utf8").includes("musl")}catch(e){return!0}}()?"musl":"gnu"}`,e);case"arm":return v("java.linux-arm-gnueabihf",e);default:throw f()}default:throw f()}},r.getJavaLibPath=function(){const e=c.default.join(__dirname,"JavaBridge.jar");if(s.default.existsSync(e)&&s.default.statSync(e).isFile())return e;throw new Error("JavaBridge.jar not found")}},242:(e,r,a)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.getJavaVersionSync=r.getJavaVersion=void 0;const n=a(230);r.getJavaVersion=async function(){const e=await(0,n.importClassAsync)("java.lang.System");return await e.getProperty("java.version")},r.getJavaVersionSync=function(){return(0,n.importClass)("java.lang.System").getPropertySync("java.version")}},973:e=>{function r(e){var r=new Error("Cannot find module '"+e+"'");throw r.code="MODULE_NOT_FOUND",r}r.keys=()=>[],r.resolve=r,r.id=973,e.exports=r},317:e=>{"use strict";e.exports=require("child_process")},896:e=>{"use strict";e.exports=require("fs")},928:e=>{"use strict";e.exports=require("path")},23:e=>{"use strict";e.exports=require("util")}},r={};function a(n){var t=r[n];if(void 0!==t)return t.exports;var o=r[n]={id:n,loaded:!1,exports:{}};return e[n].call(o.exports,o,o.exports,a),o.loaded=!0,o.exports}return a.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),a.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),a.p="",a(772)})())); | ||
//# sourceMappingURL=index.prod.min.js.map |
@@ -38,2 +38,12 @@ /* tslint:disable */ | ||
asyncSuffix?: string | ||
/** | ||
* If true, any Java exception will be returned in the `cause` | ||
* field of the thrown `JavaError` even in async methods. | ||
* Enabling this will cause the stack trace of the | ||
* JavaScript error to be lost. | ||
* If not specified, the value from the global configuration will be used. | ||
* | ||
* @since 2.6.0 | ||
*/ | ||
asyncJavaExceptionObjects?: boolean | ||
} | ||
@@ -76,2 +86,12 @@ /** | ||
asyncSuffix?: string | ||
/** | ||
* If true, any Java exception will be returned in the `cause` | ||
* field of the thrown `JavaError` even in async methods. | ||
* Enabling this will cause the stack trace of the | ||
* JavaScript error to be lost. | ||
* Default is false. | ||
* | ||
* @since 2.6.0 | ||
*/ | ||
asyncJavaExceptionObjects?: boolean | ||
} | ||
@@ -141,2 +161,9 @@ /** Options for the interface proxies */ | ||
* Will return a promise that resolves to the class instance. | ||
* | ||
* If the underlying Java throwable should be contained in the error object, | ||
* set `asyncJavaExceptionObjects` to `true`. This will cause the JavaScript | ||
* stack trace to be lost. Setting this option in the global config will | ||
* **not** affect this method, this option has to be set each time this | ||
* method is called. | ||
* | ||
* @see importClass | ||
@@ -300,2 +327,18 @@ */ | ||
/** | ||
* Get whether to return Java exceptions as objects in async methods. | ||
* | ||
* @since 2.6.0 | ||
*/ | ||
get asyncJavaExceptionObjects(): boolean | null | ||
/** | ||
* If true, any Java exception will be returned in the `cause` | ||
* field of the thrown `JavaError` even in async methods. | ||
* Enabling this will cause the stack trace of the | ||
* JavaScript error to be lost. | ||
* If not specified, the value from the global configuration will be used. | ||
* | ||
* @since 2.6.0 | ||
*/ | ||
set asyncJavaExceptionObjects(value: boolean | undefined | null) | ||
/** | ||
* Override the whole config. | ||
@@ -302,0 +345,0 @@ * If you want to change only a single field, use the static setters instead. |
@@ -38,2 +38,12 @@ /* tslint:disable */ | ||
asyncSuffix?: string | ||
/** | ||
* If true, any Java exception will be returned in the `cause` | ||
* field of the thrown `JavaError` even in async methods. | ||
* Enabling this will cause the stack trace of the | ||
* JavaScript error to be lost. | ||
* If not specified, the value from the global configuration will be used. | ||
* | ||
* @since 2.6.0 | ||
*/ | ||
asyncJavaExceptionObjects?: boolean | ||
} | ||
@@ -76,2 +86,12 @@ /** | ||
asyncSuffix?: string | ||
/** | ||
* If true, any Java exception will be returned in the `cause` | ||
* field of the thrown `JavaError` even in async methods. | ||
* Enabling this will cause the stack trace of the | ||
* JavaScript error to be lost. | ||
* Default is false. | ||
* | ||
* @since 2.6.0 | ||
*/ | ||
asyncJavaExceptionObjects?: boolean | ||
} | ||
@@ -141,2 +161,9 @@ /** Options for the interface proxies */ | ||
* Will return a promise that resolves to the class instance. | ||
* | ||
* If the underlying Java throwable should be contained in the error object, | ||
* set `asyncJavaExceptionObjects` to `true`. This will cause the JavaScript | ||
* stack trace to be lost. Setting this option in the global config will | ||
* **not** affect this method, this option has to be set each time this | ||
* method is called. | ||
* | ||
* @see importClass | ||
@@ -300,2 +327,18 @@ */ | ||
/** | ||
* Get whether to return Java exceptions as objects in async methods. | ||
* | ||
* @since 2.6.0 | ||
*/ | ||
get asyncJavaExceptionObjects(): boolean | null | ||
/** | ||
* If true, any Java exception will be returned in the `cause` | ||
* field of the thrown `JavaError` even in async methods. | ||
* Enabling this will cause the stack trace of the | ||
* JavaScript error to be lost. | ||
* If not specified, the value from the global configuration will be used. | ||
* | ||
* @since 2.6.0 | ||
*/ | ||
set asyncJavaExceptionObjects(value: boolean | undefined | null) | ||
/** | ||
* Override the whole config. | ||
@@ -302,0 +345,0 @@ * If you want to change only a single field, use the static setters instead. |
{ | ||
"name": "java-bridge", | ||
"version": "2.5.2", | ||
"version": "2.6.0", | ||
"main": "dist/index.prod.min.js", | ||
@@ -110,10 +110,10 @@ "types": "dist/index.d.ts", | ||
"optionalDependencies": { | ||
"java-bridge-win32-x64-msvc": "2.5.2", | ||
"java-bridge-darwin-x64": "2.5.2", | ||
"java-bridge-linux-x64-gnu": "2.5.2", | ||
"java-bridge-darwin-arm64": "2.5.2", | ||
"java-bridge-win32-ia32-msvc": "2.5.2", | ||
"java-bridge-linux-arm64-gnu": "2.5.2", | ||
"java-bridge-linux-x64-musl": "2.5.2" | ||
"java-bridge-win32-x64-msvc": "2.6.0", | ||
"java-bridge-darwin-x64": "2.6.0", | ||
"java-bridge-linux-x64-gnu": "2.6.0", | ||
"java-bridge-darwin-arm64": "2.6.0", | ||
"java-bridge-win32-ia32-msvc": "2.6.0", | ||
"java-bridge-linux-arm64-gnu": "2.6.0", | ||
"java-bridge-linux-x64-musl": "2.6.0" | ||
} | ||
} |
157
README.md
@@ -8,3 +8,4 @@ # java-bridge | ||
A bridge between Node.js programs and Java APIs written in Rust using [napi-rs](https://napi.rs/) | ||
A bridge between Node.js programs and Java APIs written in Rust | ||
using [napi-rs](https://napi.rs/) | ||
to provide a fast and memory-safe interface between the two languages. | ||
@@ -18,5 +19,7 @@ | ||
The full documentation of this package is available [here](https://markusjx.github.io/node-java-bridge/). | ||
The full documentation of this package is | ||
available [here](https://markusjx.github.io/node-java-bridge/). | ||
**NOTE: As of version `2.1.0`, this package has been renamed from `@markusjx/java` to `java-bridge`.** | ||
**NOTE: As of version `2.1.0`, this package has been renamed from `@markusjx/java` | ||
to `java-bridge`.** | ||
@@ -29,13 +32,18 @@ ## Installation | ||
_Note: In order to use this package on windows, you'll need to install the [Visual C++ Redistributable for Visual Studio 2015](https://www.microsoft.com/en-gb/download/details.aspx?id=48145)._ | ||
_Note: In order to use this package on windows, you'll need to install | ||
the [Visual C++ Redistributable for Visual Studio 2015](https://www.microsoft.com/en-gb/download/details.aspx?id=48145)._ | ||
## Command line interface | ||
This module also provides a command line interface that allows you to generate typescript definitions for your java classes. | ||
The command line interface is called `java-ts-definition-generator` and can be installed using `npm install -g java-ts-definition-generator`. | ||
The full documentation can be found [here](https://github.com/MarkusJx/java-ts-definition-generator). | ||
This module also provides a command line interface that allows you to generate typescript | ||
definitions for your java classes. | ||
The command line interface is called `java-ts-definition-generator` and can be installed | ||
using `npm install -g java-ts-definition-generator`. | ||
The full documentation can be | ||
found [here](https://github.com/MarkusJx/java-ts-definition-generator). | ||
## Build instructions | ||
_This is only required for development purposes. When installing the package using `npm i`, you can skip this._ | ||
_This is only required for development purposes. When installing the package | ||
using `npm i`, you can skip this._ | ||
@@ -60,3 +68,4 @@ In order to build this project, you should install | ||
> _✅ = Pre-compiled binaries are available_<br> _`-` = Pre-compiled binaries are not available_ | ||
> _✅ = Pre-compiled binaries are available_<br> _`-` = Pre-compiled binaries are not | ||
> available_ | ||
@@ -89,3 +98,5 @@ | Operating System | i686 | x64 | arm | arm64 | | ||
Create a new Java VM using the [`ensureJvm`](https://markusjx.github.io/node-java-bridge/functions/ensureJvm.html) method. | ||
Create a new Java VM using | ||
the [`ensureJvm`](https://markusjx.github.io/node-java-bridge/functions/ensureJvm.html) | ||
method. | ||
Calling this after the jvm has already been created will do nothing. | ||
@@ -108,4 +119,6 @@ Destroying the jvm manually is not (yet) supported. | ||
You can pass extra options to the jvm when creating it, for example requesting a specific jvm version, | ||
specifying the location of the jvm native library or passing additional arguments to the jvm. | ||
You can pass extra options to the jvm when creating it, for example requesting a specific | ||
jvm version, | ||
specifying the location of the jvm native library or passing additional arguments to the | ||
jvm. | ||
@@ -122,6 +135,8 @@ ```ts | ||
All threads will be attached as daemon threads, allowing the jvm to exit when the main thread exits. | ||
All threads will be attached as daemon threads, allowing the jvm to exit when the main | ||
thread exits. | ||
This behaviour can not be changed, as it may introduce undefined behaviour. | ||
Important note on jvm options: Different arguments must be parsed as separate strings in the `opts` array. | ||
Important note on jvm options: Different arguments must be parsed as separate strings in | ||
the `opts` array. | ||
Otherwise, the jvm will not be able to parse the arguments correctly. | ||
@@ -131,3 +146,4 @@ | ||
When using this package in a packaged electron application, you should unpack this package and | ||
When using this package in a packaged electron application, you should unpack this package | ||
and | ||
the appropriate binaries for your platform into the `app.asar.unpacked` folder. When using | ||
@@ -147,3 +163,4 @@ electron-builder, you can do this by adding the following to your `package.json`: | ||
Additionally, you should set the `isPackagedElectron` option to `true` when creating the jvm: | ||
Additionally, you should set the `isPackagedElectron` option to `true` when creating the | ||
jvm: | ||
@@ -156,3 +173,4 @@ ```ts | ||
This option _should_ not have any effect when not using electron or not having the application packaged. | ||
This option _should_ not have any effect when not using electron or not having the | ||
application packaged. | ||
@@ -166,3 +184,4 @@ ### Inject a JAR into the class path | ||
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). | ||
from the JVM using [`importClass`](#synchronous-calls) | ||
or [`importClassAsync`](#asynchronous-calls). | ||
@@ -190,5 +209,7 @@ ```ts | ||
If you want to use Java APIs in a synchronous way, you can use the synchronous API of this module. | ||
If you want to use Java APIs in a synchronous way, you can use the synchronous API of this | ||
module. | ||
Any call to the Java API will be executed in the same thread as your node process so this | ||
may cause your program to hang until the execution is finished. But - in contrast to the asynchronous API - | ||
may cause your program to hang until the execution is finished. But - in contrast to the | ||
asynchronous API - | ||
these calls are a lot faster as no extra threads need to be created/attached to the JVM. | ||
@@ -201,4 +222,7 @@ | ||
If you are looking for asynchronous calls, take a look at the next section. | ||
In order to import a class synchronously, you can use the [`importClass`](https://markusjx.github.io/node-java-bridge/functions/importClass.html) function. | ||
Using this method does not affect your ability to call any method of the class asynchronously. | ||
In order to import a class synchronously, you can use | ||
the [`importClass`](https://markusjx.github.io/node-java-bridge/functions/importClass.html) | ||
function. | ||
Using this method does not affect your ability to call any method of the class | ||
asynchronously. | ||
@@ -224,12 +248,18 @@ ```ts | ||
If you want to use Java APIs in an asynchronous way, you can use the asynchronous API of this module. | ||
Any call to the Java API will be executed in a separate thread and the execution will not block your program. | ||
This is in general a lot slower as the synchronous API but allows the program to run more smoothly. | ||
If you want to use Java APIs in an asynchronous way, you can use the asynchronous API of | ||
this module. | ||
Any call to the Java API will be executed in a separate thread and the execution will not | ||
block your program. | ||
This is in general a lot slower as the synchronous API but allows the program to run more | ||
smoothly. | ||
If you want to improve the performance of the asynchronous API, you can force the module to attach | ||
any thread as a daemon thread to the JVM. This allows the program to not constantly attach new threads | ||
If you want to improve the performance of the asynchronous API, you can force the module | ||
to attach | ||
any thread as a daemon thread to the JVM. This allows the program to not constantly attach | ||
new threads | ||
to the JVM as the old ones can be reused and thus improves the performance. | ||
In order to import a class asynchronously, you can use the | ||
[`importClassAsync`](https://markusjx.github.io/node-java-bridge/functions/importClassAsync.html) function. | ||
[`importClassAsync`](https://markusjx.github.io/node-java-bridge/functions/importClassAsync.html) | ||
function. | ||
@@ -255,3 +285,4 @@ ```ts | ||
you must call that method using the interface asynchronously as Node.js is single threaded | ||
and can't wait for the java method to return while calling the proxy method at the same time. | ||
and can't wait for the java method to return while calling the proxy method at the same | ||
time. | ||
@@ -292,2 +323,46 @@ ```ts | ||
## Errors | ||
Errors thrown in the java process are returned as `JavaError` objects. | ||
These objects contain the error message, the full stack trace (including the java, node | ||
and rust process) and the java throwable that caused | ||
the error. The throwable is only available when the error was thrown in the java process | ||
and not in the node process and if the call was a synchronous call. | ||
The throwable can be accessed using the `cause` property of the | ||
`JavaError` object. | ||
```ts | ||
import type { JavaError } from 'java-bridge'; | ||
try { | ||
// Call a method that throws an error | ||
someInstance.someMethodSync(); | ||
} catch (e: unknown) { | ||
const throwable = (e as JavaError).cause; | ||
throwable.printStackTraceSync(); | ||
} | ||
``` | ||
If you want to access the Java throwable from an asynchronous call, you | ||
need to enable | ||
the `asyncJavaExceptionObjects` [config option](https://markusjx.github.io/node-java-bridge/variables/config.html) | ||
before or while importing the class. | ||
Enabling this will cause the stack trace of the JavaScript error to be lost. | ||
```ts | ||
import { importClass } from 'java-bridge'; | ||
const SomeClass = importClass('path.to.SomeClass', { | ||
asyncJavaExceptionObjects: true, | ||
}); | ||
try { | ||
await SomeClass.someMethod(); | ||
} catch (e: unknown) { | ||
const throwable = (e as JavaError).cause; | ||
throwable.printStackTraceSync(); | ||
} | ||
``` | ||
## Logging | ||
@@ -315,13 +390,20 @@ | ||
1. Any basic value such as `string`, `number`, `boolean` or `BigInt` may be passed to methods accepting matching | ||
1. Any basic value such as `string`, `number`, `boolean` or `BigInt` may be passed to | ||
methods accepting matching | ||
types | ||
2. `string` values will always be converted to `java.lang.String` | ||
3. `string` values with just one character may be converted to `char` or `java.lang.Char` if required | ||
4. Thus, in order to pass a `char` to a java method, use a `string` containing just one character | ||
5. `number` values will be converted to `int`, `long`, `double`, `float`, `java.lang.Integer`, | ||
`java.lang.Long`, `java.lang.Double` or `java.lang.Float` depending on the type the java function to call requires | ||
3. `string` values with just one character may be converted to `char` or `java.lang.Char` | ||
if required | ||
4. Thus, in order to pass a `char` to a java method, use a `string` containing just one | ||
character | ||
5. `number` values will be converted | ||
to `int`, `long`, `double`, `float`, `java.lang.Integer`, | ||
`java.lang.Long`, `java.lang.Double` or `java.lang.Float` depending on the type the | ||
java function to call requires | ||
6. `boolean` values will be converted to either `boolean` or `java.lang.Boolean` | ||
7. `BigInt` values will be converted to either `long` or `java.lang.Long` | ||
8. Arrays will be converted to java arrays. Java arrays may only contain a single value type, therefore the type of | ||
the first element in the array will be chosen as the array type, empty arrays need no conversions. | ||
8. Arrays will be converted to java arrays. Java arrays may only contain a single value | ||
type, therefore the type of | ||
the first element in the array will be chosen as the array type, empty arrays need no | ||
conversions. | ||
9. `java.lang.String` values will be converted to `string` | ||
@@ -333,3 +415,4 @@ 10. `int`, `double`, `float`, `java.lang.Integer`, `java.lang.Double` or `java.lang.Float` | ||
13. `char` or `java.lang.Character` values will be converted to `string` | ||
14. Java arrays will be converted to javascript arrays, applying the rules mentioned above except | ||
14. Java arrays will be converted to javascript arrays, applying the rules mentioned above | ||
except | ||
15. Byte arrays will be converted to `Buffer` and vice-versa |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
165620
1869
401