我用 java-imaging-utilities API 处理图片,获得图片的所有颜色数,在本机运行一切正常。但是把jar包提交到服务器,运行后报 HeadlessException 。服务器是没有显示器、鼠标、键盘的。请问该如何处理?

解决方案 »

  1.   

    -Djava.awt.headless=true以前csdn上有一篇文章讲到过
      

  2.   

    不行啊,还是报, java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:121)
    我不知道那个java-imaging-utilities底层是怎么实现的。
      

  3.   

    不懂,前面看了sun的网站也是这样写的http://java.sun.com/products/java-media/2D/reference/faqs/index.htmlQ: I have an application that reads, writes, and processes images (but does not display them) using Java2D. When I run my application on Solaris or Linux, it complains that X11 is not available. What can I do to make my application work in this environment? 
    A: When AWT is initialized, it expects to find an Xserver, regardless of whether it is needed for actual display. 
    Although many image operations using the Image I/O APIs or the JAI optional package might not have any obvious need for display, they often invoke code that needs an AWT resource. For example, calling getGraphics() on a BufferedImage initializes AWT and causes these error messages seen by developers. There is no way to say that a particular API does or does not have this problem; it depends on what particular operations are being invoked, and might also depend on what the application does with the images that is not strictly related to any of the APIs cited above. There are two possible solutions. As of J2SE 1.4 (and above), the preferred solution is to use the "headless AWT toolkit". This feature allows you to use the Java2D API in a server-side application without the need for a display environment. To specify the headless environment, run your application with the following system property: 
        -Djava.awt.headless=true
    For releases prior to J2SE 1.4 you can provide a "pseudo X-server" to emulate a display environment. One of these Xserver emulators is Xvfb, available for download at http://www.x.org. Another possibility is to start a VNC server (http://www.realvnc.com) and then run your application in that environment. Xvfb does still have one possible use in J2SE 1.4: A server application may need to display to an Xserver, but requires no user interaction. The headless toolkit won't support this situation, but xvfb will. This is a completely hypothetical scenario and it is not clear if any real world application exhibits such a behavior. 
      

  4.   

    如果你服务器上本身都没有相应地硬件设备的话,那么你在代码中调用这些硬件设备,就会产生这样HeadlessException 异常,你给服务器加上设备应该就行了。