cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Neo4j install-service; where to set java_home path?

Gosforth
Graph Buddy

Hi,

I have two versions of Java at my server 1.8 and 11 (other apps require 1.8)
For neo4j.bat I simply set java_home inserting line:

SET "JAVA_HOME=C:\Program Files\Java\jdk-11.0.4"

How to manage it for neo4j install-service?
Where I should set java_home? Tried $javaPath = 'C:\Program Files\Java\jdk-11.0.4' and '$javaCMD = 'C:\Program Files\Java\jdk-11.0.4\bin'' in Get-Java.ps1 yet it does not work. Same about ' $javaPath = 'C:\Program Files\Java\jdk-11.0.4' in this file.

Regards

1 ACCEPTED SOLUTION

I think it is being set automatically only once during the service creation based on the JAVA_HOME environment variable value that is set at that time, after which JAVA_HOME is ignored by the service (but, obviously, it is still being respected by the CLI executions of Neo4j commands).

Initially my Neo4j service was created with JAVA_HOME set to OpenJDK 14.
Then I installed Oracle JDK 1.8 and set JAVA_HOME to it because other software required it.
Neo4j happily kept using OpenJDK 14, according to ProcessExplorer.
What I tried to do is to run <neo4j_home>\bin\neo4j uninstall-service with the new JAVA_HOME setting and it did not let me, complaining about the JRE version compatibility with Neo4j. This served as the extra proof that up until that point the service was starting Neo4j using the old, somehow preserved, JAVA_HOME setting.

So I think the right sequence of steps is the following:

  • set JAVA_HOME temporarily to the JRE location that is known to be compatible with the Neo4j version (I am not sure whether the system-wide setting is necessary or a session setting will suffice)
  • run <neo4j_home>\bin\neo4j uninstall-service
  • set JAVA_HOME to the new JRE location
  • try running <neo4j_home>\bin\neo4j install-service to re-create the Neo4j service
  • set the JAVA_HOME system environment variable to whatever other programs need - Neo4j service should be ignoring it

P.S. I could not find a neo4j.conf setting for this, which is strange. Maybe this inability to change the location of a JRE for an already created and tested system service was the intentional protection against silly people?

View solution in original post

4 REPLIES 4

12kunal34
Graph Fellow

You need to set path in environment variable of system.
go to mycomputer's properties and check environment variable

Gosforth
Graph Buddy

Read the post before you answer.

I think it is being set automatically only once during the service creation based on the JAVA_HOME environment variable value that is set at that time, after which JAVA_HOME is ignored by the service (but, obviously, it is still being respected by the CLI executions of Neo4j commands).

Initially my Neo4j service was created with JAVA_HOME set to OpenJDK 14.
Then I installed Oracle JDK 1.8 and set JAVA_HOME to it because other software required it.
Neo4j happily kept using OpenJDK 14, according to ProcessExplorer.
What I tried to do is to run <neo4j_home>\bin\neo4j uninstall-service with the new JAVA_HOME setting and it did not let me, complaining about the JRE version compatibility with Neo4j. This served as the extra proof that up until that point the service was starting Neo4j using the old, somehow preserved, JAVA_HOME setting.

So I think the right sequence of steps is the following:

  • set JAVA_HOME temporarily to the JRE location that is known to be compatible with the Neo4j version (I am not sure whether the system-wide setting is necessary or a session setting will suffice)
  • run <neo4j_home>\bin\neo4j uninstall-service
  • set JAVA_HOME to the new JRE location
  • try running <neo4j_home>\bin\neo4j install-service to re-create the Neo4j service
  • set the JAVA_HOME system environment variable to whatever other programs need - Neo4j service should be ignoring it

P.S. I could not find a neo4j.conf setting for this, which is strange. Maybe this inability to change the location of a JRE for an already created and tested system service was the intentional protection against silly people?

For Linux services you can chose to only set java 11 for neo4j and or this you need to edit the service configuration file
systemctl edit neo4j
Force the environment variable when your service starts

[Service]
# Set the JAVA_HOME to java 11 
#(consider future upgrade of java 11 since this is an absolute path ) 
Environment="JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.11.0.9-2.el8_4.x86_64/"
# The user and group which the service runs as.
User=neo4j
Group=neo4j
# If it takes longer than this then the shutdown is considered to have failed.
# This may need to be increased if the system serves long-running transactions.
TimeoutSec=120