背景
在我的Linux笔记本上面运行一个jar包的时候报错如下:
代码语言:shell复制Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: /usr/lib/jvm/java-17-openjdk-amd64/lib/libawt_xawt.so
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2393)
at java.base/java.lang.Runtime.load0(Runtime.java:755)
at java.base/java.lang.System.load(System.java:1953)
at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
at java.base/jdk.internal.loader.NativeLibraries.findFromPaths(NativeLibraries.java:315)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:285)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2398)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
at java.base/java.lang.System.loadLibrary(System.java:1989)
at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:1388)
at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:1386)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at java.desktop/java.awt.Toolkit.loadLibraries(Toolkit.java:1385)
at java.desktop/java.awt.Toolkit.initStatic(Toolkit.java:1423)
at java.desktop/java.awt.Toolkit.<clinit>(Toolkit.java:1397)
at java.desktop/javax.swing.UIManager.getSystemLookAndFeelClassName(UIManager.java:668)
at us.deathmarine.luyten.Luyten.main(Luyten.java:47)
查看文件发现文件并不存在:
代码语言:shell复制➜ tmp ll /usr/lib/jvm/java-17-openjdk-amd64/lib/libawt_xawt.so
ls: cannot access '/usr/lib/jvm/java-17-openjdk-amd64/lib/libawt_xawt.so': No such file or directory
于是重新安装了下openjdk17
代码语言:shell复制apt install openjdk-17-jdk
此时发现这个文件存在了。
代码语言:shell复制➜ tmp ll /usr/lib/jvm/java-17-openjdk-amd64/lib/libawt_xawt.so
-rw-r--r-- 1 root root 464K Jun 12 02:08 /usr/lib/jvm/java-17-openjdk-amd64/lib/libawt_xawt.so
发现jar包也能正常运行了。
思考
- 为什么Linux自带的jdk会缺少一部分包。需要手动安装之后才可以。可以通过安装日志看到,之前安装的少了
openjdk-17-jdk openjdk-17-jdk-headless openjdk-17-jre
居然少了全部的包。想不通为什么。
➜ tmp apt install openjdk-17-jdk
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
glx-alternative-mesa update-glx
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
openjdk-17-jdk-headless openjdk-17-jre
Suggested packages:
openjdk-17-demo openjdk-17-source visualvm
The following NEW packages will be installed:
openjdk-17-jdk openjdk-17-jdk-headless openjdk-17-jre
0 upgraded, 3 newly installed, 0 to remove and 7 not upgraded.
Need to get 71.4 MB of archives.
After this operation, 79.0 MB of additional disk space will be used.
Do you want to continue? Y/n y