What is happening
The error is obviously normal since the native zabbix-java-gateway
is compiled with a recent version of Java, and you are adopting a default legacy version of Java.
How to Fix (with minor changes, keeping your custom JDK)
You can keep your custom Java JDK as default, and fix this.
Fortunately, the package zabbix-java-gateway
supports a simple way to adopt whatever java version. Also, you do not even need to install an extra Java version, since you already have installed the needed OpenJDK as dependency of Zabbix Java Gateway.
You just need to force the Zabbix Java Gateway to adopt OpenJDK again, just for that executable.
Create this file:
/etc/default/zabbix-java-gateway
And put a similar content:
JAVA=/opt/path-to-your-jdk/java
For example for Ubuntu 22.04 LTS, this is a valid content for that file:
JAVA=/usr/lib/jvm/java-11-openjdk-amd64/bin/java
If you are not sure about the correct Java path of your OpenJDK, double-check with this command:
update-alternatives --list java | grep openjdk
At this point just restart your service:
sudo systemctl restart zabbix-java-gateway
And everything should be OK.
In this way, you keep your custom JDK, but Zabbix Java Gateway uses the native one.
And now just a note about why that ↑ works.
This works since the systemd daemon of the Zabbix Java Gateway works in this way (here from Ubuntu 22.04 current LTS):
$ systemctl cat zabbix-java-gateway
# /etc/systemd/system/zabbix-java-gateway.service
[Unit]
Description=Zabbix Java Gateway
After=syslog.target
After=network.target
[Service]
Type=forking
KillMode=process
PIDFile=/run/zabbix/zabbix_java_gateway.pid
ExecStart=/usr/sbin/zabbix_java_gateway
SuccessExitStatus=143
User=zabbix
Group=zabbix
[Install]
WantedBy=multi-user.target
And if you inspect the executable mentioned in ExecStart
, it has this internal logic:
...
if [ -r "/etc/default/zabbix-java-gateway" ]; then
. /etc/default/zabbix-java-gateway
fi
...
JAVA=${JAVA:-java}
...
COMMAND_LINE="$JAVA
...
exec $COMMAND_LINE
So this really means the Zabbix Java Gateway does this at startup:
- execute the file
/etc/default/zabbix-java-gateway
if available
- assume the variable
$JAVA
to "java"
as default - since the meaning of that bash line is: NEWVAR=${VARNAME:-defaultvalue}
- execute
$JAVA
("java"
) as default
In short,
That is why you can just edit the file /etc/default/zabbix-java-gateway
. I thank the package maintainer for this native package done so well for Debian and Ubuntu and that allows this minimal solution.