-1

I am using tomcat 8.5.15. version for my project and I have one question about setting up java environment variables for tomcat.

I have installed JRE on my windows machine and set the environment variable as JAVA_HOME instead of JRE_HOME.

  1. catalina.bat start command works fine, though I define this variable wrong.
  2. service.bat install %servicename% is throwing an error. says The JAVA_HOME environment variable is not defined correctly. NB: JAVA_HOME should point to a JDK not a JRE

But, when i say catalina.bat debug , it throws the same error by saying NB: JAVA_HOME should point to a JDK not a JRE

why catalina.bat is failing to check for java environment variable if I run catalina.bat start ? How to achieve the same behavior for both of these scripts ?

Thank you, Ras Dama.

Ras
  • 543
  • 1
  • 9
  • 25

1 Answers1

0

No.It is not a bug. JRE by only includes the Java Runtime , it is okay to use it only if you just want to run Java application and nothing more. But to use the JVM debugger feature , you must use JDK which the location is specified by JAVA_HOME.

catalina.bat start will only run Tomcat , so JRE is enough.

catalina.bat debug will enable the debugger and run Tomcat , so JDK is required.

In fact, RUNNING.txt already explains this behaviour:

(3.2) Set JRE_HOME or JAVA_HOME (required)

These variables are used to specify location of a Java Runtime Environment or of a Java Development Kit that is used to start Tomcat.

The JRE_HOME variable is used to specify location of a JRE. The JAVA_HOME variable is used to specify location of a JDK.

Using JAVA_HOME provides access to certain additional startup options that are not allowed when JRE_HOME is used.

If both JRE_HOME and JAVA_HOME are specified, JRE_HOME is used.

And in the catalina.bat , it also mentions :

#   JAVA_HOME       Must point at your Java Development Kit installation.
#                   Required to run the with the "debug" argument.
#
#   JRE_HOME        Must point at your Java Runtime installation.
#                   Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
#                   are both set, JRE_HOME is used.

Also see : What is the difference between JDK and JRE?


Updated on 18-June-2018 :

Real Problem is, if you install JRE and set JRE path as JAVA_HOME instead of JRE_HOME catalina.bat is able to find the jre path and starts normally. But, service.bat looks for jre folder inside JAVA_HOME and fails. if you define JRE_HOME variable, service.bat also works great.

It is because catalina.bat will call setclasspath.bat internally and setclasspath.bat try to ensure JAVA_HOME and JRE_HOME are valid and consistent. In your case , it will set JRE_HOME to JAVA_HOME , so catalina.bat is able to find the JRE path even you did not set JRE_HOME.

service.bat have its own checking logic for the JAVA_HOME / JRE_HOME. So , if you want to install JRE only but only set JAVA_HOME , try to execute setclasspath.bat before catalina.bat.

Ken Chan
  • 84,777
  • 26
  • 143
  • 172
  • Hi Chan, Thanks for answering. But, my question is still same why catalina.bat is failing to check for java environment variable if I run catalina.bat start ? How to achieve the same behavior for both of these scripts ? In mycase, I installed JRE , defined environment variable as JAVA_HOME instead of JRE_HOME. `catalina.bat start` works fine with this. `service.bat install tomcat8.5` throws an error . saying `NB: JAVA_HOME should point to a JDK not a JRE` – Ras Jun 16 '18 at 19:13
  • You need to install JDK . Then set JAVA_HOME to the JDK 's location. There is no way to run in debug mode if you only install JRE. – Ken Chan Jun 16 '18 at 20:02
  • `We don't need JDK. JRE should be fine, if we set JRE_HOME environment variable.` I believe you haven't got the scenario. First thing is, JRE is enough to run tomcat. Second thing is, catalina.bat and service.bat are not having the similar behavior in identifying java. `Real Problem is, if you install JRE and set JRE path as JAVA_HOME instead of JRE_HOME catalina.bat is able to find the jre path and starts normally. But, service.bat looks for jre folder inside JAVA_HOME and fails. if you define JRE_HOME variable, service.bat also works great.` – Ras Jun 17 '18 at 21:27
  • OK. Finally understand your question. See my revised answers. – Ken Chan Jun 18 '18 at 08:04