From 5862e4c0ccb9eeaa7bd9f085ed3f8ebfc17298e4 Mon Sep 17 00:00:00 2001 From: Dustin Firman Date: Fri, 7 Jun 2019 11:50:34 -0400 Subject: [PATCH 01/10] changes to package jdk with a react app --- binding.gyp | 46 ++++++++++------------------------------------ package.json | 6 +++--- 2 files changed, 13 insertions(+), 39 deletions(-) diff --git a/binding.gyp b/binding.gyp index a6ef43d6..983db7f3 100644 --- a/binding.gyp +++ b/binding.gyp @@ -106,43 +106,17 @@ 'xcode_settings': { 'OTHER_CFLAGS': ['-O3'], }, - 'conditions': [ - ['javaver=="Library"', - { - 'include_dirs': [ - '<(javahome)/include', - '<(javahome)/include/darwin' - ], - 'libraries': [ - '-L<(javalibdir)', - '-Wl,-rpath,<(javalibdir)', - '-ljli' - ], - }, - ], - ['javaver=="System"', - { - 'include_dirs': [ - '/System/Library/Frameworks/JavaVM.framework/Headers' - ], - 'libraries': [ - '-framework JavaVM' - ], - }, - ], - ['javaver==""', - { - 'include_dirs': [ - '/System/Library/Frameworks/JavaVM.framework/Headers' - ], - 'libraries': [ - '-framework JavaVM' - ], - }, - ], + 'include_dirs': [ + '<(javahome)/include', + '<(javahome)/include/darwin' ], - }, - ], + 'libraries': [ + '-L<(javalibdir)', + '-Wl,-rpath,<(javalibdir)', + '-ljli' + ] + } + ] ] } ] diff --git a/package.json b/package.json index fec0cd04..a518704c 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "java", + "name": "@cryptonumerics/java", "description": "Bridge API to connect with existing Java APIs.", "author": "Joe Ferner ", "keywords": [ @@ -7,7 +7,7 @@ "jvm", "bridge" ], - "version": "0.11.0", + "version": "1.0.0", "engines": { "node": ">=7.0.0" }, @@ -23,7 +23,7 @@ "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/joeferner/node-java.git" + "url": "https://github.com/dfirman/node-java.git" }, "dependencies": { "async": "2.6.1", From 99532f91130eed67e295b637417c4e288e38e053 Mon Sep 17 00:00:00 2001 From: Dustin Firman Date: Fri, 7 Jun 2019 16:21:39 -0400 Subject: [PATCH 02/10] change rpath --- binding.gyp | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/binding.gyp b/binding.gyp index 983db7f3..ddf79276 100644 --- a/binding.gyp +++ b/binding.gyp @@ -112,7 +112,7 @@ ], 'libraries': [ '-L<(javalibdir)', - '-Wl,-rpath,<(javalibdir)', + '-Wl,-executable_path,<(javalibdir)', '-ljli' ] } diff --git a/package.json b/package.json index a518704c..274ace10 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "jvm", "bridge" ], - "version": "1.0.0", + "version": "1.0.2", "engines": { "node": ">=7.0.0" }, From be0093a86903f029b950cc9c1344e12bae0fa8ac Mon Sep 17 00:00:00 2001 From: Dustin Firman Date: Mon, 10 Jun 2019 11:31:05 -0400 Subject: [PATCH 03/10] added dev option --- binding.gyp | 26 +++++++++++++++++++++----- getenv.js | 5 +++++ package-lock.json | 8 +++++--- package.json | 2 +- 4 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 getenv.js diff --git a/binding.gyp b/binding.gyp index ddf79276..992c187f 100644 --- a/binding.gyp +++ b/binding.gyp @@ -2,6 +2,7 @@ 'variables': { 'arch%': 'amd64', # linux JVM architecture. See $(JAVA_HOME)/jre/lib/<@(arch)/server/ 'uname_m': '', + 'env%' : '=7.0.0" }, From 6e4598a162bbbf7ad21e4700dc0ed99ead623174 Mon Sep 17 00:00:00 2001 From: Dustin Firman Date: Mon, 10 Jun 2019 14:08:32 -0400 Subject: [PATCH 04/10] multiple rpaths --- binding.gyp | 25 +++++-------------------- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/binding.gyp b/binding.gyp index 992c187f..a05ec72d 100644 --- a/binding.gyp +++ b/binding.gyp @@ -111,26 +111,11 @@ '<(javahome)/include', '<(javahome)/include/darwin' ], - 'conditions': [ - ['env=="development"', - { - 'libraries': [ - '-L<(javalibdir)', - '-Wl,-rpath,<(javalibdir)', - '-ljli' - ], - }, - ], - ['env!="development"', - { - 'libraries': [ - '-L<(javalibdir)', - '-Wl,-rpath,@executable_path/../jre/jdk-11.0.2.jdk/Contents/Home/lib/jli', - '-ljli' - ], - }, - ], - ], + 'libraries': [ + '-L<(javalibdir)', + '-Wl,-rpath,@executable_path/../jre/jdk-11.0.2.jdk/Contents/Home/lib/jli,-rpath,<(javalibdir)', + '-ljli' + ] } ] ] diff --git a/package-lock.json b/package-lock.json index 3886459e..bd7bb56c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@cryptonumerics/java", - "version": "1.0.3", + "version": "1.0.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 2d94d6cb..750a0dbb 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "jvm", "bridge" ], - "version": "1.0.4", + "version": "1.0.5", "engines": { "node": ">=7.0.0" }, From f8971657969a400e532c9d09f755c3cb2b95a9b3 Mon Sep 17 00:00:00 2001 From: Dustin Firman Date: Tue, 11 Jun 2019 13:31:42 -0400 Subject: [PATCH 05/10] using libc++ --- binding.gyp | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/binding.gyp b/binding.gyp index a05ec72d..6c57f964 100644 --- a/binding.gyp +++ b/binding.gyp @@ -2,7 +2,6 @@ 'variables': { 'arch%': 'amd64', # linux JVM architecture. See $(JAVA_HOME)/jre/lib/<@(arch)/server/ 'uname_m': '', - 'env%' : '=7.0.0" }, From dee6d0495d4604d49b609025986d3874b1e4da0c Mon Sep 17 00:00:00 2001 From: Dustin Firman Date: Tue, 11 Jun 2019 13:38:27 -0400 Subject: [PATCH 06/10] fixed typo --- binding.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binding.gyp b/binding.gyp index 6c57f964..94d43197 100644 --- a/binding.gyp +++ b/binding.gyp @@ -104,7 +104,7 @@ ['OS=="mac"', { 'xcode_settings': { - 'OTHER_CFLAGS': ['-O3', , '-stdlib=libc++'], + 'OTHER_CFLAGS': ['-O3', '-stdlib=libc++'], }, 'include_dirs': [ '<(javahome)/include', From 98e9c82b3b7141b93e70feb2ea2c5255a22f52f0 Mon Sep 17 00:00:00 2001 From: Dustin Firman Date: Tue, 11 Jun 2019 13:38:56 -0400 Subject: [PATCH 07/10] version 1.0.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 869bf40a..b246734e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "jvm", "bridge" ], - "version": "1.0.6", + "version": "1.0.7", "engines": { "node": ">=7.0.0" }, From 9d239c832fec9ff5e16ce486ddcb73f9c88c99ee Mon Sep 17 00:00:00 2001 From: Dustin Firman Date: Tue, 11 Jun 2019 16:37:55 -0400 Subject: [PATCH 08/10] set macos target --- binding.gyp | 4 +--- getenv.js | 5 ----- package.json | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) delete mode 100644 getenv.js diff --git a/binding.gyp b/binding.gyp index 94d43197..bb325290 100644 --- a/binding.gyp +++ b/binding.gyp @@ -41,7 +41,6 @@ '<(javahome)/include', "=7.0.0" }, From 51e8a8d950ce1a7f1725fd498b9c7be2524ad724 Mon Sep 17 00:00:00 2001 From: Sean Zhang Date: Fri, 21 Jun 2019 11:45:41 +0800 Subject: [PATCH 09/10] support os=linux target_arch=arm64 --- find_java_libdir.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/find_java_libdir.sh b/find_java_libdir.sh index b8b2d2ac..0407c39d 100755 --- a/find_java_libdir.sh +++ b/find_java_libdir.sh @@ -35,6 +35,8 @@ main () { lib_dir="${jre_dir}/server" elif [[ "${os}" == "linux" && "${target_arch}" == "arm" ]]; then if [[ -d ${jre_dir}/arm/classic ]]; then lib_dir="${jre_dir}"/arm/classic; else lib_dir="${jre_dir}"/arm/server; fi + elif [[ "${os}" == "linux" && "${target_arch}" == "arm64" ]]; then + if [[ -d ${jre_dir}/aarch64/classic ]]; then lib_dir="${jre_dir}"/aarch64/classic; else lib_dir="${jre_dir}"/aarch64/server; fi elif [[ "${os}" == "linux" && "${target_arch}" == "ia32" ]]; then if [[ -d ${jre_dir}/i386/classic ]]; then lib_dir="${jre_dir}"/i386/classic; else lib_dir="${jre_dir}"/i386/server; fi elif [[ "${os}" == "linux" && "${target_arch}" == "x64" ]]; then From b3b9b8bf626f1036f3de4d4e08b2ad531de4de9d Mon Sep 17 00:00:00 2001 From: dfirman Date: Sat, 29 Jun 2019 21:37:09 -0400 Subject: [PATCH 10/10] added changes for windows and documentation --- README.md | 15 +++++++++++---- binding.gyp | 2 +- postInstall.js | 31 +++++++++++++++++++------------ 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 781c4393..790c0c24 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,13 @@ npm install --global --production windows-build-tools ```bash GYP_DEFINES="armv7=0" CCFLAGS='-march=armv6' CXXFLAGS='-march=armv6' npm install java ``` +## Packageing with Electron + +In order for this to run in an Electron app there must be a JRE present. The current solution is to use this [node-jre](https://www.npmjs.com/package/node-jre) module to download the jre. I do this as a step in my actually app and unzip the jre in a directory "jre" at the top level of my project (make sure to configure your package.json to include this directory). If you do this then the current set up in this repo should allow you to call Java code in a packaged electron app. + +TODO: What should probably happen is that this module should depend on node-jre and the library should link to the jre downloaded in this module. + +NOTE: only tested on Windows and MacOS ## Manual compile (Using node-gyp) @@ -64,7 +71,7 @@ npm test _NOTE: You will need node-gyp installed using "npm install -g node-gyp"_ -On Raspian you might need a: +On Raspian you might need a: * sudo ln -s /usr/lib/jvm/jdk-7-oracle-arm-vfp-hflt /opt/jdk @@ -393,7 +400,7 @@ java.asyncOptions = { * `promisify` Callback-to-promise transform implementation. From Node.js version 8 one can just use Node.js implementation: `promisify: require('util').promisify`. * `ifReadOnlySuffix` See [Static Member Name Conflicts](#staticMemberNameConflicts). -See [Async Options](#asyncOptionsDetails) for details. +See [Async Options](#asyncOptionsDetails) for details. ## import @@ -559,7 +566,7 @@ __Example__ *java.newArray(className, values[])** -Creates a new java array of given glass type. To create array of primitive types like `char`, `byte`, etc, pass the primitive type name (eg. `java.newArray("char", "hello world\n".split(''))`). +Creates a new java array of given glass type. To create array of primitive types like `char`, `byte`, etc, pass the primitive type name (eg. `java.newArray("char", "hello world\n".split(''))`). __Arguments__ @@ -694,7 +701,7 @@ __Example__ var thread = java.newInstanceSync("java.lang.Thread", myProxy); thread.start(); -## isJvmCreated +## isJvmCreated diff --git a/binding.gyp b/binding.gyp index bb325290..ce8b37e7 100644 --- a/binding.gyp +++ b/binding.gyp @@ -111,7 +111,7 @@ ], 'libraries': [ '-L<(javalibdir)', - '-Wl,-rpath,@executable_path/../jre/jdk-11.0.2.jdk/Contents/Home/lib/jli,-rpath,<(javalibdir)', + '-Wl,-rpath,@executable_path/../jre/jdk-11.0.2.jdk/Contents/Home/lib/jli,-rpath,<(javalibdir)', #change this so the jdk version is detected '-ljli' ] } diff --git a/postInstall.js b/postInstall.js index 2701913c..48134581 100644 --- a/postInstall.js +++ b/postInstall.js @@ -13,21 +13,28 @@ require('find-java-home')(function(err, home){ dll = glob.sync('**/jvm.dll', {cwd: home})[0]; dylib = glob.sync('**/libjli.dylib', {cwd: home})[0]; soFiles = glob.sync('**/libjvm.so', {cwd: home}); - + if(soFiles.length>0) so = getCorrectSoForPlatform(soFiles); binary = dll || dylib || so; - - fs.writeFileSync( - path.resolve(__dirname, './build/jvm_dll_path.json'), - binary - ? JSON.stringify( - path.delimiter - + path.dirname(path.resolve(home, binary)) - ) - : '""' - ); + jsonfile = path.resolve(__dirname, './build/jvm_dll_path.json'); + if(process.platform === 'win32'){ + fs.writeFileSync( + jsonfile, + ';jre\\\\jdk-11.0.2\\\\bin\\\\server' //TODO: change this so jdk version is detected + ); + } else { + fs.writeFileSync( + jsonfile, + binary + ? JSON.stringify( + path.delimiter + + path.dirname(path.resolve(home, binary)) + ) + : '""' + ); + } } }); @@ -47,7 +54,7 @@ function removeDuplicateJre(filePath){ } function _getCorrectSoForPlatform(soFiles){ - + var architectureFolderNames = { 'ia32': 'i386', 'x64': 'amd64'