自從將 UniFi Network Application 升級至 7.2.92 之後,已經有好幾個月沒去關注它。直到今天才注意到它的管理介面提示有 7.3.76 的更新可以升級,豈料升級之後就導致 UniFi Network Application 無法啟動。研究之後發現 7.3.76 已經不支援 Java 8 所以得要升級至 Java 11,不過心裡也納悶自己早就將系統中的 Java 由 8 升級至 11 了,怎麼還會有 Java 版本匹配的問題呢? 仔細檢查過後,發現原來系統中同時存在 Java 8 與 Java 11 兩個版本,所以導致使用錯誤的 Java 8 ,造成無法啟動的問題。如果您也有 7.3.76 升級後發生 JNI 的問題,可以看看這一篇的說明,也許可以幫助到您。
問題內容
UniFi Network Application 由 7.2.92 升級到 7.3.76 之後,發生下列錯誤而無法順利啟動:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/ubnt/ace/Launcher has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)
問題的根源
自己使用的系統是 CentOS Stream 8,先檢查目前路徑中的 Java 版本:
$ java -version
openjdk version "1.8.0_362-ea"
OpenJDK Runtime Environment (build 1.8.0_362-ea-b01)
OpenJDK 64-Bit Server VM (build 25.362-b01, mixed mode)
這個結果與先前認知到已經將 Java 8 升級到 Java 11 的印象有出入,再次檢查相關安裝的 Java 套件:
$ rpm -qa | grep java
java-11-openjdk-headless-11.0.18.0.9-0.3.ea.el8.x86_64
java-11-openjdk-devel-11.0.18.0.9-0.3.ea.el8.x86_64
java-11-openjdk-11.0.18.0.9-0.3.ea.el8.x86_64
java-1.8.0-openjdk-1.8.0.362.b01-0.3.ea.el8.x86_64
java-1.8.0-openjdk-headless-1.8.0.362.b01-0.3.ea.el8.x86_64
java-1.8.0-openjdk-devel-1.8.0.362.b01-0.3.ea.el8.x86_64
問題有可能出在未移除 Java 8 ,導致 UniFi Network Application 還是使用 Java 8 啟動,先將 Java 8 移除試試看:
$ rpm -e java-1.8.0-openjdk java-1.8.0-openjdk-devel java-1.8.0-openjdk-headless
移除之後,再檢查 Java 的版本是否是預期的 Java 11 :
$ java -version
openjdk version "11.0.18-ea" 2023-01-17 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.18.0.9-0.3.ea.el8) (build 11.0.18-ea+9-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.18.0.9-0.3.ea.el8) (build 11.0.18-ea+9-LTS, mixed mode, sharing)
接著,再重新將 UniFi Network Application 啟動看看:
$ service unifi start
Redirecting to /bin/systemctl start unifi.service
$ service unifi status
Redirecting to /bin/systemctl status unifi.service
● unifi.service - Ubiquiti UniFi Controller
Loaded: loaded (/etc/systemd/system/unifi.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2023-02-03 03:40:31 UTC; 5s ago
Process: 1902436 ExecStop=/usr/bin/java -jar /opt/UniFi/lib/ace.jar stop (code=exited, status=0/SUCCESS)
Main PID: 1906240 (java)
Tasks: 46 (limit: 23265)
Memory: 504.1M
CGroup: /system.slice/unifi.service
├─1906240 /usr/bin/java -Xmx1024M -jar /opt/UniFi/lib/ace.jar start
└─1906288 bin/mongod --dbpath /opt/UniFi-7.3.76/data/db --port 27117 --unixSocketPrefix /opt/UniFi-7.3.76/run --logRotate reopen --logappend --logpath /opt/UniFi-7.3.76/logs/mongod.log --pidfile>
Feb 03 03:40:31 centos-stream-8.cine.idv.tw systemd[1]: Started Ubiquiti UniFi Controller.
就這樣,原先無法啟動的 UniFi Network Application 7.3.76 順利給恢復正常運作囉!