Skip to content
Merged
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ npm test

_NOTE: You will need node-gyp installed using "npm install -g node-gyp"_

On Raspian you might need a:

* sudo ln -s /usr/lib/jvm/jdk-7-oracle-arm-vfp-hflt /opt/jdk

Some issues with the OpenSDK7 so take the Oracle version for compiling.

## Docker

If you want to play with node-java but don't want to setup the build environment you can run it in docker.
Expand Down
3 changes: 3 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
['OS=="mac"', {
'javaver%' : "<!(awk -F/ -v h=`node findJavaHome.js` 'BEGIN {n=split(h, a); print a[2]; exit}')"
}],
['OS=="linux" and target_arch=="arm"', {
'javalibdir%': "<!(h=\"`node findJavaHome.js`\" sh -c 'if [ -d \"$h/jre/lib/arm/classic\" ]; then echo $h/jre/arm/i386/classic; else echo $h/jre/lib/arm/server; fi')"
}],
['OS=="linux" and target_arch=="ia32"', {
'javalibdir%': "<!(h=\"`node findJavaHome.js`\" sh -c 'if [ -d \"$h/jre/lib/i386/classic\" ]; then echo $h/jre/lib/i386/classic; else echo $h/jre/lib/i386/server; fi')"
}],
Expand Down
16 changes: 16 additions & 0 deletions compile-java-code.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
set JAVA_VERSION=1.7

set OUTFILE="%TMP%\findJavaHome.txt"
node findJavaHome.js > %OUTFILE%
set /p JAVA_HOME=<%OUTFILE%

set JAVAC_OPTS=-source %JAVA_VERSION% -target %JAVA_VERSION% -bootclasspath "%JAVA_HOME%\jre\lib\rt.jar"

cd test
"%JAVA_HOME%\bin\javac" %JAVAC_OPTS% *.java

cd ..\src-java\node
"%JAVA_HOME%\bin\javac" %JAVAC_OPTS% *.java

cd ..\..\
"%JAVA_HOME%\bin\javah" -classpath src-java -d .\src node.NodeDynamicProxyClass
8 changes: 8 additions & 0 deletions compile-java8-code.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set JAVA_VERSION=1.8

set OUTFILE="%TMP%\findJavaHome.txt"
node findJavaHome.js > %OUTFILE%
set /p JAVA_HOME=<%OUTFILE%

cd test8
"%JAVA_HOME%\bin\javac" -source %JAVA_VERSION% *.java
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"jvm",
"bridge"
],
"version": "0.7.0",
"version": "0.7.2",
"engines": {
"node": ">=0.10.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/java.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ NAN_METHOD(Java::newProxy) {
jclass objectClazz = env->FindClass("java/lang/Object");
jobjectArray methodArgs = env->NewObjectArray(2, objectClazz, NULL);
env->SetObjectArrayElement(methodArgs, 0, v8ToJava(env, Nan::New<v8::String>(s_nativeBindingLocation.c_str()).ToLocalChecked()));
env->SetObjectArrayElement(methodArgs, 1, longToJavaLongObj(env, (long)dynamicProxyData));
env->SetObjectArrayElement(methodArgs, 1, longToJavaLongObj(env, (jlong)dynamicProxyData));
jobject method = javaFindConstructor(env, clazz, methodArgs);
if(method == NULL) {
std::ostringstream errStr;
Expand Down
Binary file added test/ListenerInterface.class
Binary file not shown.
3 changes: 3 additions & 0 deletions test/ListenerInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface ListenerInterface {
void onEvent(java.util.ArrayList<String> list, java.lang.Runtime runtime);
}
Binary file added test/ListenerTester.class
Binary file not shown.
19 changes: 19 additions & 0 deletions test/ListenerTester.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class ListenerTester {
private ListenerInterface _listener;

public void setListener(ListenerInterface listener) {
this._listener = listener;
}

public void raiseEvent() {
if(this._listener == null)
return;

java.util.ArrayList<String> list = new java.util.ArrayList<String>();
list.add("hello");
list.add("from");
list.add("Java");

this._listener.onEvent(list, java.lang.Runtime.getRuntime());
}
}
18 changes: 18 additions & 0 deletions test/dynamicProxy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ exports['Dynamic Proxy'] = nodeunit.testCase({
test.done();
},

"Listener test": function (test) {
var runData = '';

var myProxy = java.newProxy('ListenerInterface', {
onEvent: function (list, runtime) {
runData = 'onEvent';
}
});

var listenerTester = java.newInstanceSync("ListenerTester");
listenerTester.setListenerSync(myProxy);
listenerTester.raiseEventSync();

test.equals(runData, 'onEvent');

test.done();
},

"thread": function (test) {
var callCount = 0;

Expand Down
5 changes: 4 additions & 1 deletion testRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ var tests = glob.sync(path.join('testAsyncOptions', '*.js'));
tests.unshift('test test8'); // Arrange to run the primary tests first, in a single process

function runTest(testArgs, done) {
var cmd = 'node_modules/.bin/nodeunit ' + testArgs;
var cmd = 'node_modules/.bin/nodeunit ';
if(process.platform == "win32")
cmd = 'node_modules\\.bin\\nodeunit ';
cmd += testArgs;
childProcess.exec(cmd, function (error, stdout, stderr) {
// It appears that nodeunit merges error output into the stdout
// so these three lines are probably useless.
Expand Down