Skip to content

Commit 0128b73

Browse files
committed
compiles and works on windows
1 parent 191cbc9 commit 0128b73

8 files changed

Lines changed: 100 additions & 13 deletions

File tree

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,23 @@ $ export JDK_LIB_DIR=/usr/local/share/jdk1.6.0_30/jre/lib/i386/client/
1111
$ npm install java
1212
```
1313

14+
## Installation Windows
15+
16+
* Install Python
17+
* Download node.js source
18+
* Run a Visual Studios command prompt
19+
* Build node.js source by running "vcbuild.bat release"
20+
* The directory where jvm.dll exists must be in the PATH.
21+
22+
```bash
23+
$ set NODE_ROOT=C:\Program Files (x86)\nodejs
24+
$ vcbuild.bat
25+
```
26+
1427
## Installation Mac
1528

1629
```bash
30+
$ ???
1731
$ npm install java
1832
```
1933

src/java.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ v8::Handle<v8::Value> Java::createJVM(JavaVM** jvm, JNIEnv** env) {
6969
v8::Local<v8::Array> classPathArray = v8::Array::Cast(*classPathValue);
7070
for(uint32_t i=0; i<classPathArray->Length(); i++) {
7171
if(i != 0) {
72-
classPath << ":"; // TODO: figure out path seperator
72+
#ifdef WIN32
73+
classPath << ";";
74+
#else
75+
classPath << ":";
76+
#endif
7377
}
7478
v8::Local<v8::Value> arrayItemValue = classPathArray->Get(i);
7579
if(!arrayItemValue->IsString()) {

src/methodCallBaton.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ MethodCallBaton::~MethodCallBaton() {
2222
}
2323

2424
void MethodCallBaton::run() {
25-
eio_custom(MethodCallBaton::EIO_MethodCall, EIO_PRI_DEFAULT, MethodCallBaton::EIO_AfterMethodCall, this);
26-
ev_ref(EV_DEFAULT_UC);
25+
uv_work_t* req = new uv_work_t();
26+
req->data = this;
27+
uv_queue_work(uv_default_loop(), req, MethodCallBaton::EIO_MethodCall, MethodCallBaton::EIO_AfterMethodCall);
2728
}
2829

2930
v8::Handle<v8::Value> MethodCallBaton::runSync() {
@@ -32,20 +33,19 @@ v8::Handle<v8::Value> MethodCallBaton::runSync() {
3233
return resultsToV8(env);
3334
}
3435

35-
/*static*/ void MethodCallBaton::EIO_MethodCall(eio_req* req) {
36+
/*static*/ void MethodCallBaton::EIO_MethodCall(uv_work_t* req) {
3637
MethodCallBaton* self = static_cast<MethodCallBaton*>(req->data);
3738
JNIEnv *env = javaAttachCurrentThread(self->m_java->getJvm());
3839
self->execute(env);
3940
javaDetachCurrentThread(self->m_java->getJvm());
4041
}
4142

42-
/*static*/ int MethodCallBaton::EIO_AfterMethodCall(eio_req* req) {
43+
/*static*/ void MethodCallBaton::EIO_AfterMethodCall(uv_work_t* req) {
4344
MethodCallBaton* self = static_cast<MethodCallBaton*>(req->data);
4445
JNIEnv *env = self->m_java->getJavaEnv();
4546
self->after(env);
46-
ev_unref(EV_DEFAULT_UC);
47+
delete req;
4748
delete self;
48-
return 0;
4949
}
5050

5151
void MethodCallBaton::after(JNIEnv *env) {

src/methodCallBaton.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#ifndef _methodcallbaton_h_
33
#define _methodcallbaton_h_
44

5+
#include "utils.h"
56
#include <v8.h>
67
#include <node.h>
78
#include <jni.h>
89
#include <list>
9-
#include "utils.h"
1010

1111
class Java;
1212
class JavaObject;
@@ -16,8 +16,8 @@ class MethodCallBaton {
1616
MethodCallBaton(Java* java, jobject method, jarray args, v8::Handle<v8::Value>& callback);
1717
virtual ~MethodCallBaton();
1818

19-
static void EIO_MethodCall(eio_req* req);
20-
static int EIO_AfterMethodCall(eio_req* req);
19+
static void EIO_MethodCall(uv_work_t* req);
20+
static void EIO_AfterMethodCall(uv_work_t* req);
2121
void run();
2222
v8::Handle<v8::Value> runSync();
2323

src/nodeJavaBridge.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ extern "C" {
1010

1111
NODE_MODULE(nodejavabridge_bindings, init);
1212
}
13+
14+
#ifdef WIN32
15+
16+
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
17+
return TRUE;
18+
}
19+
20+
#endif

src/utils.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ std::string javaToString(JNIEnv *env, jstring str) {
6262

6363
std::string javaObjectToString(JNIEnv *env, jobject obj) {
6464
if(obj == NULL) {
65-
return "";
65+
return "(null)";
6666
}
6767
jclass objClazz = env->GetObjectClass(obj);
6868
jmethodID methodId = env->GetMethodID(objClazz, "toString", "()Ljava/lang/String;");
@@ -161,8 +161,9 @@ void javaDetachCurrentThread(JavaVM* jvm) {
161161

162162
jvalueType javaGetType(JNIEnv *env, jclass type) {
163163
// TODO: has to be a better way
164-
const char *typeStr = javaObjectToString(env, type).c_str();
165-
//printf("%s\n", typeStr);
164+
std::string str = javaObjectToString(env, type);
165+
const char *typeStr = str.c_str();
166+
//printf("javaGetType: %s\n", typeStr);
166167
if(strcmp(typeStr, "int") == 0) {
167168
return TYPE_INT;
168169
} else if(strcmp(typeStr, "long") == 0) {

src/utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef _utils_h_
33
#define _utils_h_
44

5+
#define BUILDING_NODE_EXTENSION 1
56
#include <v8.h>
67
#include <jni.h>
78
#include <list>

vcbuild.bat

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
@echo OFF
2+
3+
echo Check for nodejs build location variable: %NODE_ROOT%
4+
if not defined NODE_ROOT goto nodebuild-not-found
5+
if not exist "%NODE_ROOT%\src\node.h" goto nodebuild-not-found
6+
if not exist "%NODE_ROOT%\deps\v8\include\v8.h" goto nodebuild-not-found
7+
if not exist "%NODE_ROOT%\deps\uv\include\uv.h" goto nodebuild-not-found
8+
9+
echo detect the location of the node.lib file
10+
set nodelibpath=
11+
if exist "%NODE_ROOT%\Release\node.lib" set nodelibpath=%NODE_ROOT%\Release
12+
if not defined nodelibpath if exist "%NODE_ROOT%\Debug\node.lib" set nodelibpath=%NODE_ROOT%\Debug
13+
if not defined nodelibpath goto nodebuild-not-found
14+
15+
echo detect java
16+
if not defined NODE_ROOT goto java-not-found
17+
if not exist "%JAVA_HOME%\include\jni.h" goto java-not-found
18+
if not exist "%JAVA_HOME%\lib\jvm.lib" goto java-not-found
19+
20+
echo Check for visual studio tools if not already loaded
21+
if defined VCINSTALLDIR goto start-compilation
22+
if not defined VS100COMNTOOLS goto msbuild-not-found
23+
if not exist "%VS100COMNTOOLS%..\..\vc\vcvarsall.bat" goto msbuild-not-found
24+
call "%VS100COMNTOOLS%..\..\vc\vcvarsall.bat"
25+
if not defined VCINSTALLDIR goto msbuild-not-found
26+
27+
:start-compilation
28+
echo Compiling...
29+
@rem "support throws" "don't strip comments" "no banner" "disable intrinsic functions" "no optimization" "calling conversion __cdecl" "no analysis" "the /I adds some folders in the include path"
30+
rem /ZI /nologo /W3 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL" /D "NODEJAVA_EXPORTS" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yu"StdAfx.h" /Fp"Debug\node-java.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /analyze- /errorReport:queue
31+
cl.exe src\*.cpp /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /EHsc /c /nologo /Oi- /Od /Gd /analyze- /I "%NODE_ROOT%\deps\v8\include" /I "%NODE_ROOT%\src" /I "%NODE_ROOT%\deps\uv\include" /I "%JAVA_HOME%\include" /I "%JAVA_HOME%\include\win32"
32+
if errorlevel 1 goto exit-error
33+
echo Done compiling. Linking...
34+
echo Using %nodelibpath%\node.lib file to link to
35+
link *.obj node.lib jvm.lib uv.lib /OUT:"nodejavabridge_bindings.dll" /NOLOGO /DLL /MANIFEST:NO /SUBSYSTEM:WINDOWS /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /LIBPATH:%nodelibpath% /LIBPATH:%nodelibpath%/lib /LIBPATH:"%JAVA_HOME%\lib"
36+
if errorlevel 1 goto exit-error
37+
echo Done linking
38+
echo Cleaning up
39+
if not exist build mkdir build
40+
if not exist build\Release mkdir build\Release
41+
move nodejavabridge_bindings.dll build\Release\nodejavabridge_bindings.node
42+
echo Finished
43+
goto exit
44+
45+
:msbuild-not-found
46+
echo Visual studio tools were not found! Please check the VS100COMNTOOLS path variable
47+
goto exit
48+
49+
:nodebuild-not-found
50+
echo Node build path not found! Please check the NODE_ROOT path variable exists and that it points to the root of the git repo where you have build
51+
goto exit
52+
53+
:java-not-found
54+
echo Java not found! Please check JAVA_HOME variable.
55+
goto exit
56+
57+
:exit-error
58+
echo An error occured. Please check the above output
59+
:exit

0 commit comments

Comments
 (0)