libawt_xawt.so
java应用添加了对图片水印和缩略图处理后,部署在ubuntu服务器,报错:
java.lang.UnsatisfiedLinkError: /mnt/jdk1.8/jre/lib/amd64/libawt_xawt.so: libXrender.so.1: cannot open shared object file: No such file or directory
java.lang.UnsatisfiedLinkError: /mnt/jdk1.8/jre/lib/amd64/libawt_xawt.so: libXtst.so.6: cannot open shared object file: No such file or directory
安装插件:
apt-get install libxrender-dev
apt-get install libxtst-dev
X11GraphicsEnvironment
重启tomcat后继续报错:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment
Caused by: java.lang.InternalError: Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable.
原因是在Linux下,用java图片jar包处理图片时,需要本地的x-server的支持,java 1.4版本以上启动时加上参数:
-Djava.awt.headless=true
对于tomcat,在catalina.sh或catalina.bat中,所有类似以下代码:
"$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
-Djava.security.manager \
-Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
在尾部添加:
-Djava.awt.headless=true \
修改后内容如下:
...
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
-Djava.awt.headless=true \
...
附:Headless mode
Headless模式是系统的一种配置模式。在该模式下,系统缺少了显示设备、键盘或鼠标,一般Linux服务端使用headless mode。
java查看headless mode:
System.setProperty("java.awt.headless","true")