Cannot start Confluence service because it claims I don't have JDK
Asked by Khiem Ngo:

I recently installed a new Confluence installation on a clean Windows Server 2019 server. Confluence starts fine when I run start-confluence.bat from an admin command prompt, but it runs in the foreground. When Confluence installed, it created a service, but I cannot get that service to start, nor can I find any logs to give me direction on what went wrong. The only error I get when attempting to start the service is:
> Windows could not start the Confluence\<numbers\> on Local Computer. For more information, review the system event log. If this is a non-Microsoft service, contact the service vendor, and refer to service-specific error code 1.

The system event log has this error:
> The Confluence\<numbers\> service terminated with the following service-specific error:  
> Incorrect function.

I tried to remove and reinstall the service, but when I attempt to either install or remove the service using the service.bat, I get the error:
> 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

I have made sure that JAVA_HOME points to the copy of OpenJDK that is included in the Confluence program directory, and even tried repointing it to a copy of that same folder at c:\\jre to try to eliminate the potential issue for folder paths with spaces that I found could be a potential issue.

Overall, this is felling like a permissions issue, but the network service appears to have full control over the entire Confluence folder, so I don't know what's missing.


Answers:
author: Khiem Ngo
body: It appears the solution was despite Confluence coming with its own copy of OpenJDK and it running perfectly fine when starting it as an administrative user, I had to install the AdoptOpenJDK separately, then add JAVA_HOME and JRE_HOME environmental variables. I was then able to remove and re-add the service and it worked. That was an utterly nonsensical solution, but it works, so whatever...

comments: author: Robert Battam
body: Check the batch file that you launch th service with, as sometimes you might find someone has set it to redeclare variables upon launch, and this will override any config file settings or environmetn variables for those same settings. I had that problem once. You can either remove them or change them to what you need.


author: salvijus
body: Hi,

I had this problem after JSM update on a server with Linux SE enabled and find out that in my case it was related to lack of executable permissions on /opt/atlassian/jira/jre/bin/java and folders inside /opt/atlassian/jira.

Maybe your case is similar...


author: Mike Rathwell
body: Hi [@Khiem Ngo](/t5/user/viewprofilepage/user-id/1555597)

I haven't run Atlassian stuff on Windows in a long time for... reasons... However, thinking back, I recall there were some things that needed to be done to get it working.

I don't *think* it's a permission issue. Rather it feels like the service isn't seeing your JAVA_HOME variable set at the system level. A quick grep of Google suggests this is a rather surprising thing. To test it, you might toss a "echo $JAVA_HOME" in the startup scripts to see what the service is seeing.

Also, do have a look at [this very good page on setting up Confluence as a Windows service](https://confluence.atlassian.com/doc/start-confluence-automatically-on-windows-as-a-service-172071.html). There are a lot of tips/tricks to making it go there.


Tags: confluence-server

server