Skip to content
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ node-java.cbp
*.iml
*.kdev4
*/.kdev_include_paths
.vscode
26 changes: 24 additions & 2 deletions lib/nodeJavaBridge.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
'use strict';

process.env.PATH += require('../build/jvm_dll_path.json');

var _ = require('lodash');
var async = require('async');
var path = require('path');
var fs = require('fs');


var binaryFileName;
if (process.platform === 'win32') {
binaryFileName = 'jvm.dll';
} else if (process.platform === 'darwin') {
binaryFileName = 'libjvm.dylib';
} else {
binaryFileName = 'libjvm.so';
}

var dll_info_path = '../build/jvm_dll_path.json';
var jvm_dll_path = '';

if (fs.existsSync(dll_info_path)) {
jvm_dll_path = require(dll_info_path).replace(path.delimiter, '');
process.env.PATH += require(dll_info_path);
}

if (!fs.existsSync(path.join(jvm_dll_path, binaryFileName))) {
require('../postInstall');
}


var binaryPath = null;
try {
if(fs.statSync && fs.statSync(path.join(__dirname, "../build/Debug/nodejavabridge_bindings.node")).isFile()) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"async": "2.0.1",
"find-java-home": "0.1.3",
"glob": "7.1.1",
"locate-java-home": "^0.1.6",
"lodash": "4.16.4",
"nan": "2.4.0"
},
Expand Down
47 changes: 27 additions & 20 deletions postInstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,74 @@ var glob = require('glob');
var fs = require('fs');
var path = require('path');
var os = require('os');
var _ = require('lodash');
require('locate-java-home')(function (err, homes) {
var homePath = _.get(homes, '[0].path');
// console.log(JSON.stringify(homes, null, 2))
// console.log('\n\n\n\n')
// console.log(home)
// console.log(homePath);

require('find-java-home')(function(err, home){
var dll;
var dylib;
var so,soFiles;
var so, soFiles;
var binary;

if(home){
dll = glob.sync('**/jvm.dll', {cwd: home})[0];
dylib = glob.sync('**/libjvm.dylib', {cwd: home})[0];
soFiles = glob.sync('**/libjvm.so', {cwd: home});

if(soFiles.length>0)

if (homePath) {
dll = glob.sync('**/jvm.dll', { cwd: homePath })[0];
dylib = glob.sync('**/libjvm.dylib', { cwd: homePath })[0];
soFiles = glob.sync('**/libjvm.so', { cwd: homePath });

if (soFiles.length > 0)
so = getCorrectSoForPlatform(soFiles);

binary = dll || dylib || so;

fs.writeFileSync(
path.resolve(__dirname, './build/jvm_dll_path.json'),
binary
? JSON.stringify(
? JSON.stringify(
path.delimiter
+ path.dirname(path.resolve(home, binary))
+ path.dirname(path.resolve(homePath, binary))
)
: '""'
: '""'
);
}
});

function getCorrectSoForPlatform(soFiles){
function getCorrectSoForPlatform(soFiles) {
var so = _getCorrectSoForPlatform(soFiles);
if (so) {
so = removeDuplicateJre(so);
}
return so;
}

function removeDuplicateJre(filePath){
while(filePath.indexOf('jre/jre')>=0){
filePath = filePath.replace('jre/jre','jre');
function removeDuplicateJre(filePath) {
while (filePath.indexOf('jre/jre') >= 0) {
filePath = filePath.replace('jre/jre', 'jre');
}
return filePath;
}

function _getCorrectSoForPlatform(soFiles){
function _getCorrectSoForPlatform(soFiles) {

var architectureFolderNames = {
'ia32': 'i386',
'x64': 'amd64'
};

if(os.platform() != 'sunos')
if (os.platform() != 'sunos')
return soFiles[0];

var requiredFolderName = architectureFolderNames[os.arch()];

for (var i = 0; i < soFiles.length; i++) {
var so = soFiles[i];

if(so.indexOf('server')>0)
if(so.indexOf(requiredFolderName)>0)
if (so.indexOf('server') > 0)
if (so.indexOf(requiredFolderName) > 0)
return so;
}

Expand Down