Repository: reef
Updated Branches:
  refs/heads/REEF-335 8c6a6535d -> fed6fb770


[REEF-2001] Driver launcher fails to find the JVM.DLL if JAVA_HOME is a JRE

This adds additional search paths for `JVM.DLL` to the C++ Bridge code.

JIRA:
  [REEF-2001](https://issues.apache.org/jira/browse/REEF-2001)

Pull Request:
  This closes #1443


Project: http://git-wip-us.apache.org/repos/asf/reef/repo
Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/fed6fb77
Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/fed6fb77
Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/fed6fb77

Branch: refs/heads/REEF-335
Commit: fed6fb77050b58cc8429adb010bffb9e2b0a23e8
Parents: 8c6a653
Author: Tyler Clintworth <tycli...@microsoft.com>
Authored: Wed Apr 4 15:22:42 2018 -0700
Committer: Markus Weimer <wei...@apache.org>
Committed: Tue Apr 10 10:44:09 2018 -0700

----------------------------------------------------------------------
 .../Org.Apache.REEF.Bridge/DriverLauncher.cpp   | 45 +++++++++++---------
 1 file changed, 26 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/reef/blob/fed6fb77/lang/cs/Org.Apache.REEF.Bridge/DriverLauncher.cpp
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Bridge/DriverLauncher.cpp 
b/lang/cs/Org.Apache.REEF.Bridge/DriverLauncher.cpp
index 1243013..38098cf 100644
--- a/lang/cs/Org.Apache.REEF.Bridge/DriverLauncher.cpp
+++ b/lang/cs/Org.Apache.REEF.Bridge/DriverLauncher.cpp
@@ -25,12 +25,13 @@ typedef jint(JNICALL *JNI_CreateJavaVM_FN)(JavaVM **pvm, 
void **penv, void *args
 LPCTSTR JAVA_HOME = L"JAVA_HOME";
 
 // Where should we try to load jvm dll from?
-// Try server version first. Path relative to $(JAVA_HOME)
-LPCTSTR JVM_DLL1 = L"\\jre\\bin\\server\\jvm.dll";
-
-// If we could not find server jvm, Try client version.
-// Path relative to $(JAVA_HOME)
-LPCTSTR JVM_DLL2 = L"\\jre\\bin\\client\\jvm.dll";
+// Try these paths relative to $(JAVA_HOME).
+LPCTSTR const JVM_DLL_PATHS[] = {
+    L"\\jre\\bin\\server\\jvm.dll",
+    L"\\jre\\bin\\client\\jvm.dll",
+    L"\\bin\\server\\jvm.dll",
+    L"\\bin\\client\\jvm.dll" };
+int JVM_DLL_PATHS_SIZE = sizeof(JVM_DLL_PATHS) / sizeof(LPCTSTR);
 
 // Name of the function that creates a java VM
 const char* JNI_CreateJavaVM_Func_Name = "JNI_CreateJavaVM";
@@ -214,26 +215,32 @@ JavaVMOption* GetJavaOptions(char *argv[], int& 
optionCount, int firstOptionOrdi
 
 int Get_CreateJavaVM_Function(JNI_CreateJavaVM_FN& fn_JNI_CreateJavaVM)
 {
-    wchar_t jvmDllPath1[maxPathBufSize];
-    wchar_t jvmDllPath2[maxPathBufSize];
-    DWORD rc = GetEnvironmentVariable(JAVA_HOME, jvmDllPath1, maxPathBufSize);
+    wchar_t javaHomePath[maxPathBufSize];
+    wchar_t jvmDllPath[maxPathBufSize];
+
+    DWORD rc = GetEnvironmentVariable(JAVA_HOME, javaHomePath, maxPathBufSize);
     if (0 == rc) {
         wprintf(L"Could not GetEnvironmentVariable %ls\n", JAVA_HOME);
         return ErrGetEnvironmentVariable;
     }
 
-    wcscat_s(jvmDllPath1, maxPathBufSize, JVM_DLL1);
+    // Try all possible dll paths
+    HMODULE jvm_dll = NULL;
+    for (int i = 0; i < JVM_DLL_PATHS_SIZE; i++) {
+        swprintf(jvmDllPath, maxPathBufSize, L"%ls%ls", javaHomePath, 
JVM_DLL_PATHS[i]);
 
-    HMODULE jvm_dll = LoadLibrary(jvmDllPath1);
-    if (jvm_dll == NULL) {
-        wprintf(L"Could not load dll %ls\n", jvmDllPath1);
-        GetEnvironmentVariable(JAVA_HOME, jvmDllPath2, maxPathBufSize);
-        wcscat_s(jvmDllPath2, maxPathBufSize, JVM_DLL2);
-        jvm_dll = LoadLibrary(jvmDllPath2);
+        jvm_dll = LoadLibrary(jvmDllPath);
         if (jvm_dll == NULL) {
-            wprintf(L"Could not load dll %ls\n", jvmDllPath2);
-            return ErrLoadLibraryJVM;
+            wprintf(L"Could not load dll %ls\n", jvmDllPath);
         }
+        else
+        {
+            break;
+        }
+    }
+
+    if (jvm_dll == NULL) {
+        return ErrLoadLibraryJVM;
     }
 
     fn_JNI_CreateJavaVM = (JNI_CreateJavaVM_FN)GetProcAddress(jvm_dll, 
JNI_CreateJavaVM_Func_Name);
@@ -279,7 +286,7 @@ int CreateJVM(JNIEnv*& env, JavaVM*& jvm, JavaVMOption* 
options, int optionCount
 //
 int CallMainMethodOfEntryClass(
     JNIEnv* env,
-    char*      argv[],
+    char*   argv[],
     int     firstArgOrdinal,
     int     argCount)
 {

Reply via email to