This seems to be similar to https://bz.apache.org/bugzilla/show_bug.cgi?id=49993, maybe the validation just needs to be enhanced. Hello, this is my first ticket in Apache Bugzilla, please bear with me. We found out, that if JAVA_HOME is wrongly configured (for example if it points to JRE instead of JDK), the service.bat script won't fail, will skip to and return exit code 0. This is misleading, as the service was not installed because of wrongly set-up JAVA_HOME. Is it possible to provide better validation and make sure, that the exit code is not 0 in case the installation of the service fails? I believe that swallowing of exceptions is not a good approach ;) Thanks!
(In reply to Jakub Moravec from comment #0) > https://bz.apache.org/bugzilla/show_bug.cgi?id=49993, maybe the validation > just needs to be enhanced. +1 > We found out, that if JAVA_HOME is wrongly configured (for example if it > points to JRE instead of JDK), the service.bat script won't fail, will skip > to and return exit code 0. JAVA_HOME should be able to point to either a JRE or JDK. Tomcat hasn't required a JDK for a very long time. > This is misleading, as the service was not installed because of wrongly > set-up JAVA_HOME. If true, I agree. > Is it possible to provide better validation and make sure, that the exit > code is not 0 in case the installation of the service fails? Probably the best way to check for JAVA_HOME validity is to actually launch the JVM with some trivial task (even just "java.exe --help") to make sure it executes successfully, would you agree? > I believe that swallowing of exceptions is not a good approach ;) Do you believe there is an error being swallowed? Which one?
Thanks for the response Christopher. I dug a bit deeper... (In reply to Christopher Schultz from comment #1) > (In reply to Jakub Moravec from comment #0) > > We found out, that if JAVA_HOME is wrongly configured (for example if it > > points to JRE instead of JDK), the service.bat script won't fail, will skip > > to and return exit code 0. > > JAVA_HOME should be able to point to either a JRE or JDK. Tomcat hasn't > required a JDK for a very long time. I noticed, that there is some logic in service.bat (for Java versions in which JDK and JRE were still distributed separately), that for example appends the '/jre' absolute path segment to the JAVA_HOME. Also, the structure of the target folder seems to be somehow validated. I'm not what is the exact reason, but I expect that due to one of those facts the script prints the following messages and skips to an end. The JAVA_HOME environment variable is not defined correctly This environment variable is needed to run this program NB: JAVA_HOME should point to a JDK not a JRE > > This is misleading, as the service was not installed because of wrongly > > set-up JAVA_HOME. > > If true, I agree. Yes, as I mentioned, the log messages are printed, but that is the only indication that services were not installed. Script return code is 0 which makes it hard to handle this issue in automated solution. > > Is it possible to provide better validation and make sure, that the exit > > code is not 0 in case the installation of the service fails? > > Probably the best way to check for JAVA_HOME validity is to actually launch > the JVM with some trivial task (even just "java.exe --help") to make sure it > executes successfully, would you agree? It sounds reasonable, but since I am not sure what is the exact cause of this issue, I cannot say that this will suffice. > > I believe that swallowing of exceptions is not a good approach ;) > > Do you believe there is an error being swallowed? Which one? I'm referring to the fact that the response code is 0 - the script is acting like nothing bad happened even though the service was not installed.
For clarity, the only change required here is that the exit code should be non-zero. The validation of JAVA_HOME and JAVA_HOME vs JRE_HOME is sufficient.
Hi Mark, changing the exit code is definitely the most important action here. That being said, my understanding is that at the moment, the validation doesn't recognize that JRE is referenced by JAVA_HOME and thus the process fails during installation of the service. If the validation was able to recognize this and fail it sooner (with proper exit code), that seems to me to be a better solution.
Your understanding is incorrect. The scripts checks the validity of JAVA_HOME and exits before it attempts to install the service if it is invalid. Fixed in: - master for 10.0.0-M8 onwards - 9.0.x for 9.0.38 onwards - 8.5.x for 8.5.58 onwards - 7.0.x for 7.0.106 onwards
Hi Mark, as far as I know, the current validation only checks that JAVA_HOME is setup, but the validation will pass even if the target of JAVA_HOME is a JRE (not a JDK), which will then cause the error I'm describing. This issue is easy to reproduce: * point JAVA_HOME to JRE (e.g. 1.8) * try to use service.bat to install the Tomcat service * the script will complete with no indication of failure, but the service is not installed
This seems like a different bug to me. JRE or JDK should be fine either way.
One of JRE_HOME, JAVA_HOME or neither is acceptable. JAVA_HOME takes priority over JRE_HOME. If neither is set, the registry is used. If JAVA_HOME is configured to point to a JRE then: - the service install is not attempted - an error message is displayed and, now that this bug is fixed - the script completes with a non-zero return code
Thank you, Mark and Christopher!