0

What is expected: There is a java web application that runs on tomcat and tomcat runs as a windows service. During the installation of the application, a windows service should be created. The following command is run by the installer to create the service. NB: The installer provides the embedded tomcat.

EmbeddedTomcat/bin/service.bat install

What is happening: The installation process runs fine until the step where windows service should be created.
Java is not installed on the PC
My assumption is as there is no java installed tomcat cannot find JRE as a result the installer cannot run the service.bat install command to create service.
Is there any way I can show tomcat the JRE location that has been provided? The installation directory looks like the following
App
->Documentation files
->EmbeddedTomcat
->->bin (tomcat folder)
->->classes (web app class files)
->->conf (tomcat folder)
->->java (JRE and JDK)
->->lib (tomcat folder)
->->webapp
->->other tomcat files
I have tried setting JAVA_HOME = C:\Program File\App\EmbeddedTomcat\java\jdk1.8.0_311
JRE_HOME = C:\Program File\App\EmbeddedTomcat\java\jre1.8.0_311
PATH = C:\Program File\App\EmbeddedTomcat\java\jdk1.8.0_311\bin
CATALINA_HOME = C:\Program File\App\EmbeddedTomcat
But didn't work. Is there any other way it can be done?

Mahmud Mridul
  • 95
  • 1
  • 9
  • Does this answer your question? [Specify JRE/JDK when starting Apache Tomcat 7](https://stackoverflow.com/questions/10458109/specify-jre-jdk-when-starting-apache-tomcat-7) – pringi May 25 '22 at 11:33
  • I understand the process but will it work on a system that doesn't have java installed? – Mahmud Mridul May 25 '22 at 11:41
  • 1
    You cannot run tomcat without java. – f1sh May 25 '22 at 11:46
  • your "EmbeddedTomcat" looks like a normal tomcat installation. If you have to use `service.bat`, then you need to set either `JAVA_HOME` or `JRE_HOME`. And you are probably not quite setting the environment variables correctly, which makes this question a ducplicate of [thsi qeustion](https://superuser.com/questions/79612/setting-and-getting-windows-environment-variables-from-the-command-prompt) – XtremeBaumer May 25 '22 at 12:00

1 Answers1

0

Can I run Tomcat without pre installed JRE?

Tomcat needs a JRE or JDK installed ... somewhere on the machine.

And the JAVA_HOME or JRE_HOME variables are the preferred way to tell the server.bat file where the installation is.

You should be able to work out what you have done wrong by reading the service.bat file. In the version I looked at, the script does the following:

rem Make sure prerequisite environment variables are set
if not "%JAVA_HOME%" == "" goto gotJdkHome
if not "%JRE_HOME%" == "" goto gotJreHome
echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
echo Service will try to guess them from the registry.
goto okJavaHome
:gotJreHome
if not exist "%JRE_HOME%\bin\java.exe" goto noJavaHome
goto okJavaHome
:gotJdkHome
if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
if not "%JRE_HOME%" == "" goto okJavaHome
set "JRE_HOME=%JAVA_HOME%"
goto okJavaHome
:noJavaHome
echo The JAVA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
echo NB: JAVA_HOME should point to a JDK not a JRE
exit /b 1

Read your copy of service.bat yourself. It may be non-standard ... or a different version to the one I looked at. (The error message seems to be different to what the above would produce.)

Anyway, the above will work with either JAVA_HOME or JRE_HOME set, provided that they are set correctly. (It would also work if with neither set, provided that there is an appropriate version of Java in the registry. But that doesn't seem to be the case for you.)

So you need to first figure out what is in C:\Program File\App\EmbeddedTomcat\java. If it is a JDK, set JAVA_HOME to the appropriate subdirectory. If it is a JRE, set JRE_HOME to the appropriate subdirectory.

If it still doesn't work, read https://superuser.com/questions/79612/setting-and-getting-windows-environment-variables-from-the-command-prompt to make sure that you understand how to set an environment variable properly on Windows.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216