diff --git a/README.md b/README.md index 009c3353..9d598b8c 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,23 @@ $ export JDK_LIB_DIR=/usr/local/share/jdk1.6.0_30/jre/lib/i386/client/ $ npm install java ``` +## Installation Windows + +* Install Python +* Download node.js source +* Run a Visual Studios command prompt +* Build node.js source by running "vcbuild.bat release" +* The directory where jvm.dll exists must be in the PATH. + +```bash +$ set NODE_ROOT=C:\Program Files (x86)\nodejs +$ vcbuild.bat +``` + ## Installation Mac ```bash +$ ??? $ npm install java ``` diff --git a/src/java.cpp b/src/java.cpp index 169cbb69..274fb3d9 100644 --- a/src/java.cpp +++ b/src/java.cpp @@ -69,7 +69,11 @@ v8::Handle Java::createJVM(JavaVM** jvm, JNIEnv** env) { v8::Local classPathArray = v8::Array::Cast(*classPathValue); for(uint32_t i=0; iLength(); i++) { if(i != 0) { - classPath << ":"; // TODO: figure out path seperator + #ifdef WIN32 + classPath << ";"; + #else + classPath << ":"; + #endif } v8::Local arrayItemValue = classPathArray->Get(i); if(!arrayItemValue->IsString()) { diff --git a/src/methodCallBaton.cpp b/src/methodCallBaton.cpp index 69738cd6..f3beb2c3 100644 --- a/src/methodCallBaton.cpp +++ b/src/methodCallBaton.cpp @@ -22,8 +22,9 @@ MethodCallBaton::~MethodCallBaton() { } void MethodCallBaton::run() { - eio_custom(MethodCallBaton::EIO_MethodCall, EIO_PRI_DEFAULT, MethodCallBaton::EIO_AfterMethodCall, this); - ev_ref(EV_DEFAULT_UC); + uv_work_t* req = new uv_work_t(); + req->data = this; + uv_queue_work(uv_default_loop(), req, MethodCallBaton::EIO_MethodCall, MethodCallBaton::EIO_AfterMethodCall); } v8::Handle MethodCallBaton::runSync() { @@ -32,20 +33,19 @@ v8::Handle MethodCallBaton::runSync() { return resultsToV8(env); } -/*static*/ void MethodCallBaton::EIO_MethodCall(eio_req* req) { +/*static*/ void MethodCallBaton::EIO_MethodCall(uv_work_t* req) { MethodCallBaton* self = static_cast(req->data); JNIEnv *env = javaAttachCurrentThread(self->m_java->getJvm()); self->execute(env); javaDetachCurrentThread(self->m_java->getJvm()); } -/*static*/ int MethodCallBaton::EIO_AfterMethodCall(eio_req* req) { +/*static*/ void MethodCallBaton::EIO_AfterMethodCall(uv_work_t* req) { MethodCallBaton* self = static_cast(req->data); JNIEnv *env = self->m_java->getJavaEnv(); self->after(env); - ev_unref(EV_DEFAULT_UC); + delete req; delete self; - return 0; } void MethodCallBaton::after(JNIEnv *env) { diff --git a/src/methodCallBaton.h b/src/methodCallBaton.h index 029c8494..2e13e4d7 100644 --- a/src/methodCallBaton.h +++ b/src/methodCallBaton.h @@ -2,11 +2,11 @@ #ifndef _methodcallbaton_h_ #define _methodcallbaton_h_ +#include "utils.h" #include #include #include #include -#include "utils.h" class Java; class JavaObject; @@ -16,8 +16,8 @@ class MethodCallBaton { MethodCallBaton(Java* java, jobject method, jarray args, v8::Handle& callback); virtual ~MethodCallBaton(); - static void EIO_MethodCall(eio_req* req); - static int EIO_AfterMethodCall(eio_req* req); + static void EIO_MethodCall(uv_work_t* req); + static void EIO_AfterMethodCall(uv_work_t* req); void run(); v8::Handle runSync(); diff --git a/src/nodeJavaBridge.cpp b/src/nodeJavaBridge.cpp index 3efcbccc..b98d1496 100644 --- a/src/nodeJavaBridge.cpp +++ b/src/nodeJavaBridge.cpp @@ -10,3 +10,11 @@ extern "C" { NODE_MODULE(nodejavabridge_bindings, init); } + +#ifdef WIN32 + +BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { + return TRUE; +} + +#endif \ No newline at end of file diff --git a/src/utils.cpp b/src/utils.cpp index 2cd28b31..259dfb1e 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -62,7 +62,7 @@ std::string javaToString(JNIEnv *env, jstring str) { std::string javaObjectToString(JNIEnv *env, jobject obj) { if(obj == NULL) { - return ""; + return "(null)"; } jclass objClazz = env->GetObjectClass(obj); jmethodID methodId = env->GetMethodID(objClazz, "toString", "()Ljava/lang/String;"); @@ -161,8 +161,9 @@ void javaDetachCurrentThread(JavaVM* jvm) { jvalueType javaGetType(JNIEnv *env, jclass type) { // TODO: has to be a better way - const char *typeStr = javaObjectToString(env, type).c_str(); - //printf("%s\n", typeStr); + std::string str = javaObjectToString(env, type); + const char *typeStr = str.c_str(); + //printf("javaGetType: %s\n", typeStr); if(strcmp(typeStr, "int") == 0) { return TYPE_INT; } else if(strcmp(typeStr, "long") == 0) { diff --git a/src/utils.h b/src/utils.h index 1d5abaf6..f8d7e73b 100644 --- a/src/utils.h +++ b/src/utils.h @@ -2,6 +2,7 @@ #ifndef _utils_h_ #define _utils_h_ +#define BUILDING_NODE_EXTENSION 1 #include #include #include diff --git a/vcbuild.bat b/vcbuild.bat new file mode 100644 index 00000000..a1cd33fc --- /dev/null +++ b/vcbuild.bat @@ -0,0 +1,59 @@ +@echo OFF + +echo Check for nodejs build location variable: %NODE_ROOT% +if not defined NODE_ROOT goto nodebuild-not-found +if not exist "%NODE_ROOT%\src\node.h" goto nodebuild-not-found +if not exist "%NODE_ROOT%\deps\v8\include\v8.h" goto nodebuild-not-found +if not exist "%NODE_ROOT%\deps\uv\include\uv.h" goto nodebuild-not-found + +echo detect the location of the node.lib file +set nodelibpath= +if exist "%NODE_ROOT%\Release\node.lib" set nodelibpath=%NODE_ROOT%\Release +if not defined nodelibpath if exist "%NODE_ROOT%\Debug\node.lib" set nodelibpath=%NODE_ROOT%\Debug +if not defined nodelibpath goto nodebuild-not-found + +echo detect java +if not defined NODE_ROOT goto java-not-found +if not exist "%JAVA_HOME%\include\jni.h" goto java-not-found +if not exist "%JAVA_HOME%\lib\jvm.lib" goto java-not-found + +echo Check for visual studio tools if not already loaded +if defined VCINSTALLDIR goto start-compilation +if not defined VS100COMNTOOLS goto msbuild-not-found +if not exist "%VS100COMNTOOLS%..\..\vc\vcvarsall.bat" goto msbuild-not-found +call "%VS100COMNTOOLS%..\..\vc\vcvarsall.bat" +if not defined VCINSTALLDIR goto msbuild-not-found + +:start-compilation +echo Compiling... +@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" +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 +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" +if errorlevel 1 goto exit-error +echo Done compiling. Linking... +echo Using %nodelibpath%\node.lib file to link to +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" +if errorlevel 1 goto exit-error +echo Done linking +echo Cleaning up +if not exist build mkdir build +if not exist build\Release mkdir build\Release +move nodejavabridge_bindings.dll build\Release\nodejavabridge_bindings.node +echo Finished +goto exit + +:msbuild-not-found +echo Visual studio tools were not found! Please check the VS100COMNTOOLS path variable +goto exit + +:nodebuild-not-found +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 +goto exit + +:java-not-found +echo Java not found! Please check JAVA_HOME variable. +goto exit + +:exit-error +echo An error occured. Please check the above output +:exit