当前位置: 首页 > Java > 正文

Could not initialize class sun.awt.X11.XToolkit异常解决

关键字:
1 星2 星3 星4 星5 星 (3 次投票, 评分: 3.67, 总分: 5)
Loading ... Loading ...
baidu_share

最近上传图片的时候报错,查看后台日志出现一下错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
SEVERE: Servlet.service() for servlet [UploadCtrl] in context with path [/hqdrm] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11.XToolkit
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:169)
	at java.awt.Toolkit$2.run(Toolkit.java:834)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:826)
	at java.awt.Image.getScaledInstance(Image.java:160)
	at table.JpgTable.compressSucai(JpgTable.java:74)
	at page.produce.Step5_2Page.print(Step5_2Page.java:64)
	at UploadCtrl.doPost(UploadCtrl.java:43)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:662)

解决问题方法:
在catalina.sh 中增加-Djava.awt.headless=true

1
JAVA_OPTS="-Xms4096m -Xmx4096m -Xss512K -XX:PermSize=256m -XX:MaxPermSize=512m -Djava.awt.headless=true"

原因:
对于一个Java服务器来说经常要处理一些图形元素,例如地图的创建或者图形和图表等。这些API基本上总是需要运行一个X-server以便能使用AWT(Abstract Window Toolkit,抽象窗口工具集)。然而,运行一个不必要的X-server并不是一种好的网络管理方式。

如果你运行在JDK1.4上,那么你将有机会运行headless服务器。

-Djava.awt.headless=true
对于JDK1.3及更低的版本,有个来自eTeks的PJA工具包(Pure Java AWT Toolkit,纯Java AWT工具集)可以使用。它是一个在配置上与Sun的1.4版非常相似的headlessJava服务器,这种配置方式包含一组-D属性标志。

本文固定链接: http://www.chepoo.com/could-not-initialize-class-sun-awt-x11-xtoolkit-error.html | IT技术精华网

Could not initialize class sun.awt.X11.XToolkit异常解决:等您坐沙发呢!

发表评论