Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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__

Expand Down Expand Up @@ -694,7 +701,7 @@ __Example__
var thread = java.newInstanceSync("java.lang.Thread", myProxy);
thread.start();

## isJvmCreated
## isJvmCreated

<a name="javaisJvmCreated" >

Expand Down
49 changes: 11 additions & 38 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
'<(javahome)/include',
"<!(node -e \"require('nan')\")",
],
'cflags': ['-O3'],
'conditions': [
['OS=="win"',
{
Expand Down Expand Up @@ -104,45 +103,19 @@
['OS=="mac"',
{
'xcode_settings': {
'OTHER_CFLAGS': ['-O3'],
'MACOSX_DEPLOYMENT_TARGET': '10.9',
},
'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,@executable_path/../jre/jdk-11.0.2.jdk/Contents/Home/lib/jli,-rpath,<(javalibdir)', #change this so the jdk version is detected
'-ljli'
]
}
]
]
}
]
Expand Down
2 changes: 2 additions & 0 deletions find_java_libdir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "java",
"name": "@cryptonumerics/java",
"description": "Bridge API to connect with existing Java APIs.",
"author": "Joe Ferner <joe@fernsroth.com>",
"keywords": [
"java",
"jvm",
"bridge"
],
"version": "0.11.0",
"version": "1.0.8",
"engines": {
"node": ">=7.0.0"
},
Expand All @@ -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",
Expand Down
31 changes: 19 additions & 12 deletions postInstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
: '""'
);
}
}
});

Expand All @@ -47,7 +54,7 @@ function removeDuplicateJre(filePath){
}

function _getCorrectSoForPlatform(soFiles){

var architectureFolderNames = {
'ia32': 'i386',
'x64': 'amd64'
Expand Down