开发者

using java.awt library in linux X11 issue

开发者 https://www.devze.com 2023-02-18 23:18 出处:网络
I am trying to create a video by combining a set of images available online using Xuggle. I implemented it as a service using JSP and Java. I\'m using the tomcat server. When I deploy it in my local s

I am trying to create a video by combining a set of images available online using Xuggle. I implemented it as a service using JSP and Java. I'm using the tomcat server. When I deploy it in my local server which runs in windows, it works fine. But when i deploy it to the linux server im getting the following error.

org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11.XToolkit
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:500)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

I guess it's the headless problem which occurs in environments without a display. Can someone tell me开发者_如何转开发 how to solve this problem ? I found online that PJA toolkit can solve this problem. but how do i use this in linux? if anyone has followed this approach can you please give me step by step instructions on how to use this in linux.


I managed to solve this problem. When no X11 Display is available on a UNIX machine (also called headless environment) or when GDI resources are low on Windows, it is impossible to compute off-screen images with java.awt.Graphics methods under a JDK version < 1.4, even if your program doesn't need to display these images. Typically, this situation happens for servlets returning dynamically generated images like pies, charts or web counters. If your JDK version is <1.4 upgrade it, because in JDK 1.4 onwards this problem is solved. And then you need to enable the headless mode. This is how it is done: If you are in Linux, enter export CATALINA_OPTS="-DJava.awt.headless=true to the /etc/profile file.

Hope this would help someone else who comes across the same problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号