Servlet给出错误java.lang.NoClassDefFoundError [英] Servlet giving error java.lang.NoClassDefFoundError
问题描述
我在我的应用程序的servlet中使用以下代码
I am using the following code in a servlet of my app
java.awt.Image awtImg = java.awt.Toolkit.getDefaultToolkit ()。createImage(str1);
当我运行应用程序并调用servlet时,我收到以下错误
When I run the application and call the servlet I get the following error
java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11.XToolkit
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:169)
java.awt.Toolkit$2.run(Toolkit.java:834)
java.security.AccessController.doPrivileged(Native Method)
java.awt.Toolkit.getDefaultToolkit(Toolkit.java:826)
noticeandreports.pdf.appendFiles.PdfFunctionsClass.addSealSpace(PdfFunctionsClass.java:198)
OJ.NoticesandReports.generate_151_OJNotice.execute(generate_151_OJNotice.java:768)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
我已经在Java版本为JDK 1.6.20的Linux机器上托管了该应用程序..
I have hosted the app on a Linux machine with Java version JDK 1.6.20..
可能导致此问题的原因......
What might be causing the issue...
noticeandreports.pdf.appendFiles.PdfFunctionsClass
是编写代码的类, OJ .NoticesandReports.generate_151_OJNotice
是调用上面类中方法的servlet ...
noticeandreports.pdf.appendFiles.PdfFunctionsClass
is the class where the code is written and OJ.NoticesandReports.generate_151_OJNotice
is the servlet that calls the method inside the above class...
推荐答案
要在服务器端应用程序中使用AWT类,我相信您需要在中运行无头模式。将servlet容器的启动更改为包括:
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.)
您可能还想考虑使用替代映像库 - 第三方映像库或 javax.imageio
包。
You might also want to consider using an alternative imaging library - either a third-party one or the javax.imageio
package.
这篇关于Servlet给出错误java.lang.NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!