华蓥市邮编,陈德修的女朋友,姐弟俩共存款260元
我之前在使用zxing生成二维码的时候,ubuntu上的tomcat报了以下两种错:这两种错有时候不是同时报的,但基本都有关键字眼awt
对于问题发生的原因,我没有进行详细的代码分析。据说是因为我的服务器没有安装视窗界面,导致缺少一部分awt的共享库。而二维码的生成需要使用到awt这个库的bufferedimage,所以就导致提示缺少文件,.so
是一种共享库文件。
1.java.lang.unsatisfiedlinkerror: /usr/local/jdk1.8/jre/lib/amd64/libawt_xawt.so: libxrender.so.1: 无法打开共享对象文件: 没有那个文件或目录
2.could not initialize class java.awt.image.bufferedimage
其实也就是网上随便找的一份zxing生成二维码的代码:
public class qrcodergenerator { public static string getencode(string content) throws exception { int width = 128; // 图像宽度 int height = 128; // 图像高度 string format = "png";// 图像类型 map<encodehinttype, object> hints = new hashmap<encodehinttype, object>(); hints.put(encodehinttype.character_set, "utf-8"); hints.put(encodehinttype.margin, 3); bitmatrix bitmatrix = new multiformatwriter().encode(content, barcodeformat.qr_code, width, height, hints);// 生成矩阵 bytearrayoutputstream outputstream = new bytearrayoutputstream(); matrixtoimagewriter.writetostream(bitmatrix, format, outputstream);// 输出图像 base64.encoder encoder = base64.getencoder(); string text = encoder.encodetostring(outputstream.tobytearray()); ioutils.closequietly(outputstream); return text; } }
public class qrcodergenerator { public static string getencode(string content) throws exception { // 加入下面一行代码即可 system.setproperty("java.awt.headless","true"); int width = 128; // 图像宽度 int height = 128; // 图像高度 string format = "png";// 图像类型 map<encodehinttype, object> hints = new hashmap<encodehinttype, object>(); hints.put(encodehinttype.character_set, "utf-8"); hints.put(encodehinttype.margin, 3); bitmatrix bitmatrix = new multiformatwriter().encode(content, barcodeformat.qr_code, width, height, hints);// 生成矩阵 bytearrayoutputstream outputstream = new bytearrayoutputstream(); matrixtoimagewriter.writetostream(bitmatrix, format, outputstream);// 输出图像 base64.encoder encoder = base64.getencoder(); string text = encoder.encodetostring(outputstream.tobytearray()); ioutils.closequietly(outputstream); return text; } }
$java_opts
加入:-djava.awt.headless=true \
可以在文件的最后一行加上这个,或者找一个没有if包括的行加上:
java_opts="$java_opts -djava.awt.headless=true"
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
浅析我对 String、StringBuilder、StringBuffer 的理解
使用IDEA搭建SSM框架的详细教程(spring + springMVC +MyBatis)
Springboot整合freemarker 404问题解决方案
引入mybatis-plus报 Invalid bound statement错误问题的解决方法
网友评论