ERROR! You do not have the Java Runtime Environment installed, please install Java JRE from https://adoptopenjdk.net/?variant=openjdk11 and try again

I am very sure I have installed jdk11, but when i start the hivemq by systemctl start hivemq, this error is always printed.

Here is how i configured java :

    export JAVA_HOME=/usr/lib/jvm/jdk-11.0.7
    export PATH=$JAVA_HOME/bin:$PATH
    export HIVEMQ_HOME=/opt/hivemq
    export HIVEMQ_USER=root

    [root@paasm1 ~]#  which java
    /usr/lib/jvm/jdk-11.0.7/bin/java
    [root@paasm1 ~]#

    [root@paasm1 ~]#  java -version
    java version "11.0.7" 2020-04-14 LTS
    Java(TM) SE Runtime Environment 18.9 (build 11.0.7+8-LTS)
    Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.7+8-LTS, mixed mode)

And here is the hivemq environment:

wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww [root@paasm1 ~]# cat /etc/systemd/system/hivemq.service
[Unit]
Description=HiveMQ Community Edition
After=network.target

[Service]
Group=root
User=root
LimitNOFILE=infinity
StandardOutput=null
StandardError=journal
WorkingDirectory=/opt/hivemq
ExecStart=/opt/hivemq/bin/![](file:///C:\Users\xiangwang\AppData\Roaming\Tencent\QQ\Temp\%W@GJ$ACOF(TYDYECOKVDYB.png)run.sh
KillMode=process
Restart=always
KillSignal=15
SuccessExitStatus=143
TimeoutStopSec=3600

[Install]
WantedBy=multi-user.target

[root@paasm1 ~]#  cat /etc/init.d/hivemq
#!/bin/bash
# Copyright 2019 dc-square GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# chkconfig: 35 90 12
# description: HiveMQ start script
#
# Set HiveMQ Home to correct path, default is /opt/hivemq
HIVEMQ_HOME=/opt/hivemq
HIVEMQ_USER=root
#
# Get function from functions library
. /etc/init.d/functions
# Start the service HiveMQ
start() {
        if ps ax | grep -v "grep" | grep -q hivemq.jar ; then
        echo -n HiveMQ server already running
        failure $"HiveMQ start"
        echo; else
        echo -n Starting HiveMQ server
        $HIVEMQ_HOME/bin/run.sh >/dev/null 2>&1 &
        ### Create the lock file ###
        touch /var/lock/subsys/hivemq
        success $"HiveMQ server started"
        echo; fi
}
# Restart the service HiveMQ
stop() {
        echo -n Stopping HiveMQ server
        #killproc hivemq
        pkill -f hivemq.jar
        #wait for cleanups
        while ps ax | grep -v "grep" | grep -q hivemq.jar;
        do
        sleep 1
        done
        ##
        if ps ax | grep -v "grep" | grep -q hivemq.jar ; then failure $"HiveMQ shutdown"; else success $"HiveMQ shutdown"; fi
        ### Now, delete the lock file ###
        rm -f /var/lock/subsys/hivemq
        echo
}
# Echo the current status of HiveMQ
status() {
	if ps ax | grep -v "grep" | grep -q hivemq.jar ; then echo HiveMQ is running; else echo HiveMQ stopped; fi
}
### main logic ###
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|reload|condrestart)
        stop
        start
        ;;
  status)
        status
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload}"
        exit 1
esac
exit 0
[root@paasm1 ~]#

Where do you export the Java Home variable? Depending on the exact location, the variable is set in different shells - or not. See https://stackoverflow.com/questions/14637979/how-to-permanently-set-path-on-linux-unix for more details.

1 Like

Thank you for the reply!

I export JAVA_HOME/PATH/HIVEMQ_HOME in the /etc/profile.

I figured out that the JAVA_HOME / PATH variable that I set in the /etc/profile can not be get in the run.sh script.
But I don’t why…

systemd is a service in the background. I think it is started before the script in /etc/profile/ is called. You could try this: https://coreos.com/os/docs/latest/using-environment-variables-in-systemd-units.html and set it inside the systemd environment.