Servlet giving error java.lang.NoClassDefFoundError

拟墨画扇 提交于 2019-11-30 10:37:13

To use AWT classes in a server side application, I believe you need to run in "headless" mode. Change your servlet container's startup to include:

-Djava.awt.headless=true

(Or set the system property within your own code if you really have to.)

You might also want to consider using an alternative imaging library - either a third-party one or the javax.imageio package.

That is almost certainly not the complete stack trace. Either that stack trace or an earlier one in the log file will tell you what caused the initialization of sun.awt.X11.XToolkit to fail.

However, I'd hazard a guess that the root cause is that the JVM running the web countainer is "headless"; i.e. it doesn't have an accessible display.

The Oracle Java Technical Article entitled "Using Headless Mode in the Java SE Platform" (by Artem Ananiev and Alla Redko, June 2006) describes the issue and what to do about it.

The solution is probably as simple as adding -Djava.awt.headless=true to the JVM options in the web container startup script. For instance, if you are using Tomcat, add that to the $JAVA_OPTS environment variable before calling catalina.sh.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!