You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2019/09/04 11:44:14 UTC

[commons-daemon] branch master updated: Fix DAEMON-404. Expand search for jvm.dll to include registry's JavaHome

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git


The following commit(s) were added to refs/heads/master by this push:
     new aa4e490  Fix DAEMON-404. Expand search for jvm.dll to include registry's JavaHome
aa4e490 is described below

commit aa4e490483c9d9d2aa0495599cb27cbf35e3721c
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Sep 4 12:44:07 2019 +0100

    Fix DAEMON-404. Expand search for jvm.dll to include registry's JavaHome
---
 src/changes/changes.xml          |  5 +++++
 src/native/windows/src/javajni.c | 27 +++++++++++++++++++++++----
 src/site/xdoc/procrun.xml        |  8 +++++++-
 3 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index eb5e620..c7c0328 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -50,6 +50,11 @@
         Procrun. Correct a regression in the fix for DAEMON-391 that caused the
         GUI to mix-up the WARN and INFO logging levels. 
       </action>
+      <action issue="DAEMON-404" type="fix" dev="markt">
+        Procrun. Expand the search for a valid Java runtime library to include
+        the current JDK home defined in the Windows registry. Fully document the
+        search algorithm used to find the Java runtime library.
+      </action>
     </release>
     <release version="1.2.0" date="2019-06-28" description="Feature and bug fix release">
       <action type="fix" dev="markt" due-to="mturk" >
diff --git a/src/native/windows/src/javajni.c b/src/native/windows/src/javajni.c
index d599236..a7f874c 100644
--- a/src/native/windows/src/javajni.c
+++ b/src/native/windows/src/javajni.c
@@ -213,10 +213,12 @@ static BOOL __apxLoadJvmDll(APXHANDLE hPool, LPCWSTR szJvmDllPath, LPCWSTR szJav
             apxLogWrite(APXLOG_MARK_DEBUG "Invalid RuntimeLib specified '%S'", dllJvmPath);
             return FALSE;
         }
+        apxLogWrite(APXLOG_MARK_DEBUG "Explicit RuntimeLib specified '%S'", dllJvmPath);
     }
     else {
     	// No explicit JVM path. Use the standard registry locations.
         dllJvmPath = apxGetJavaSoftRuntimeLib(NULL);
+        apxLogWrite(APXLOG_MARK_DEBUG "No explicit RuntimeLib specified. Checking registry. Found '%S'", dllJvmPath);
     }
 
     if (GetFileAttributesW(dllJvmPath) == INVALID_FILE_ATTRIBUTES) {
@@ -224,27 +226,44 @@ static BOOL __apxLoadJvmDll(APXHANDLE hPool, LPCWSTR szJvmDllPath, LPCWSTR szJav
          * Check from Jre JavaHome registry key directly
          */
         LPWSTR szJreHome = apxGetJavaSoftHome(NULL, TRUE);
-        apxLogWrite(APXLOG_MARK_DEBUG "Invalid RuntimeLib '%S'", dllJvmPath);
         if (szJreHome) {
-            apxLogWrite(APXLOG_MARK_DEBUG "Using Jre JavaHome '%S'", szJreHome);
+            apxLogWrite(APXLOG_MARK_DEBUG "Invalid RuntimeLib '%S', Checking registry for JRE home. Found '%S'", dllJvmPath, szJreHome);
             lstrlcpyW(jreAltPath, SIZ_PATHLEN, szJreHome);
             lstrlcatW(jreAltPath, SIZ_PATHLEN, L"\\bin\\server\\jvm.dll");
             dllJvmPath = jreAltPath;
+        } else {
+            apxLogWrite(APXLOG_MARK_DEBUG "Invalid RuntimeLib '%S', Checking registry for JRE home. None found.", dllJvmPath);
         }
     }
 
     if (GetFileAttributesW(dllJvmPath) == INVALID_FILE_ATTRIBUTES) {
-        /* DAEMON-247: JavaSoft registry keys are invalid
+        /* DAEMON-247: JavaSoft JRE registry keys are invalid / not present
          * Check from Procrun's JavaHome registry key
          */
         if (szJavaHome) {
-            apxLogWrite(APXLOG_MARK_DEBUG "Using JavaHome '%S'", szJavaHome);
+            apxLogWrite(APXLOG_MARK_DEBUG "Using explicitly configured JavaHome '%S'", szJavaHome);
             lstrlcpyW(jreAltPath, SIZ_PATHLEN, szJavaHome);
             lstrlcatW(jreAltPath, SIZ_PATHLEN, L"\\bin\\server\\jvm.dll");
             dllJvmPath = jreAltPath;
         }
     }
 
+    if (GetFileAttributesW(dllJvmPath) == INVALID_FILE_ATTRIBUTES) {
+        /* DAEMON-404: JRE home in registry invalid / not present.
+         * Explicit JavaHome invalid / not present
+         * Check from JDK JavaHome registry key directly
+         */
+        LPWSTR szJdkHome = apxGetJavaSoftHome(NULL, FALSE);
+        if (szJdkHome) {
+            apxLogWrite(APXLOG_MARK_DEBUG "Invalid RuntimeLib '%S', Checking registry for JDK home. Found '%S'", dllJvmPath, szJdkHome);
+            lstrlcpyW(jreAltPath, SIZ_PATHLEN, szJdkHome);
+            lstrlcatW(jreAltPath, SIZ_PATHLEN, L"\\bin\\server\\jvm.dll");
+            dllJvmPath = jreAltPath;
+        } else {
+            apxLogWrite(APXLOG_MARK_DEBUG "Invalid RuntimeLib '%S', Checking registry for JDK home. None found.", dllJvmPath);
+        }
+    }
+
     /* Suppress the not found system popup message */
     errMode = SetErrorMode(SEM_FAILCRITICALERRORS);
 
diff --git a/src/site/xdoc/procrun.xml b/src/site/xdoc/procrun.xml
index 9a49b81..70217b1 100644
--- a/src/site/xdoc/procrun.xml
+++ b/src/site/xdoc/procrun.xml
@@ -383,7 +383,13 @@ will add the new value(s) to any existing value(s).
     <td>--Jvm</td>
     <td>auto</td>
     <td>Use either <b>auto</b> (i.e. find the JVM from the Windows registry) or specify the full path to the <b>jvm.dll</b>.
-        You can use environment variable expansion here.</td>
+        You can use environment variable expansion here. When auto is specified the following search order is used:
+        <ol>
+        <li>The current Java runtime library as defined in the registry</li>
+        <li>The current JRE as defined in the registry</li>
+        <li>The explicitly configured JavaHome for the service</li>
+        <li>The current JDK as defined in the registry</li>
+        </ol></td>
     </tr>
     <tr>
     <td>++JvmOptions</td>