Bug 62391 - Unable to Install Windows Service with Server JRE
Summary: Unable to Install Windows Service with Server JRE
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Packaging (show other bugs)
Version: 8.5.x-trunk
Hardware: PC All
: P2 normal (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-20 22:12 UTC by Igal Sapir
Modified: 2018-06-05 19:23 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Igal Sapir 2018-05-20 22:12:50 UTC
When attempting to install Tomcat as a Windows service, bin/service.bat checks for the existence of java.exe and javaw.exe in the JRE's bin directory and fails if either does not exist.

java.exe exists on all of the Java distributions for Windows, but javaw.exe exists only on distributions that utilize GUI.

The Server JRE, which is the recommended distribution for server deployments does not include javaw.exe, and therefore the service installation from service.bat fails.

I checked with both Java 1.8u171 and Java 10.0.1:

$ ls -al server-jre\jdk1.8.0_171\bin\ | grep java
-rwxr-xr-x 1 Admin None  16808 Mar 28 17:15 java-rmi.exe
-rwxr-xr-x 1 Admin None 207784 Mar 28 17:15 java.exe
-rwxr-xr-x 1 Admin None  16808 Mar 28 17:15 javac.exe

$ ls -al server-jre\jdk-10.0.1\bin\ | grep java
-rwxr-xr-x 1 Admin None  150448 Mar 26 19:02 java.dll
-rwxr-xr-x 1 Admin None  232368 Mar 26 19:02 java.exe
-rwxr-xr-x 1 Admin None   17840 Mar 26 19:02 javac.exe
-rwxr-xr-x 1 Admin None  166320 Mar 26 19:02 javajpeg.dll

The fix is very easy.  The line

    if not exist "%JRE_HOME%\bin\javaw.exe" goto noJavaHome

at https://github.com/apache/tomcat/blob/trunk/bin/service.bat#L55 should be removed.
Comment 1 Mark Thomas 2018-05-23 06:31:04 UTC
The proposed change makes sense to me. A couple of questions come to mind:
1. Why was the script written to check for both files? Is there any explanation in the svn history?
2. Does the Windows installer have a similar problem?
Comment 2 Christopher Schultz 2018-05-23 16:09:46 UTC
IIRC, java.exe will always open a command-prompt to run the command. That's why javaw.exe exists.

For a "server install", does that mean that a console needs to be available because java.exe will run instead of javaw.exe?

Windows Service probably works regardless.
Comment 3 Mark Thomas 2018-05-23 17:53:21 UTC
Take a look at the svn history. As far as I can tell, javaw.exe has never been used.
Comment 4 Igal Sapir 2018-05-23 18:04:19 UTC
> IIRC, java.exe will always open a command-prompt to run the command. That's why javaw.exe exists.

Right, but that is for Windowed, GUI applications where you don't want a console window to open with the application.  I believe that that's where the `w` comes from in `javaw`.

> Take a look at the svn history. As far as I can tell, javaw.exe has never been used.

I have been using Tomcat with the Server JRE on Windows for a few years now.  The Windows service runs well with the `java.exe` only.  

The only problem is with the installation of the Windows Service via `service.bat`.

If there is no objection then I will go ahead and remove the offensive line.
Comment 5 Igal Sapir 2018-05-23 19:56:39 UTC
(In reply to Mark Thomas from comment #1)
> <snip/>
> 2. Does the Windows installer have a similar problem?

I just ran the Windows Service Installer executable of Tomcat 9.0.8 on Windows 10 and pointed it to the Server JRE which does not have the `javaw.exe` file.

The installation completed with no errors and the service started successfully, so this issue does not affect the Windows Service Installer.
Comment 6 Mark Thomas 2018-06-05 19:23:26 UTC
Fixed in:
- trunk for 9.0.9 onwards
- 8.5.x for 8.5.32 onwards
- 8.0.x for 8.0.53 onwards
- 7.0.x for 7.0.89 onwards

I removed all references to javaw.exe from the scripts. I also checked for references anywhere else in the source code. There were none.