1
我使用Jfreechart來創建圖表。我正在創建圖表的BufferedImage
並將其寫入OutputStream
。Jfreechart沒有X11
它的顯示環境工作正常,但其在headless
環境中工作不正常。
請幫助你如何在這樣的環境中工作。
例外,我在日誌了:
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/WebAdmin] threw exception [Handler processing failed; nested exception is java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.] with root cause
java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:110)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:102)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
at sun.swing.SwingUtilities2.isLocalDisplay(SwingUtilities2.java:1457)
at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults(MetalLookAndFeel.java:1556)
at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults(BasicLookAndFeel.java:148)
at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults(MetalLookAndFeel.java:1592)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:536)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:576)
at javax.swing.UIManager.initializeDefaultLAF(UIManager.java:1345)
at javax.swing.UIManager.initialize(UIManager.java:1455)
at javax.swing.UIManager.maybeInitialize(UIManager.java:1422)
at javax.swing.UIManager.getDefaults(UIManager.java:656)
at javax.swing.UIManager.getColor(UIManager.java:698)
at org.jfree.chart.JFreeChart.<clinit>(JFreeChart.java:263)
at org.jfree.chart.ChartFactory.createBarChart(ChartFactory.java:893)
而且catalina.sh的一部分,我已經編輯:
# JSSE_HOME (Optional) May point at your Java Secure Sockets Extension
# (JSSE) installation, whose JAR files will be added to the
# system class path used to start Tomcat.
#
# CATALINA_PID (Optional) Path of the file which should contains the pid
# of catalina startup java process, when start (fork) is used
#
# $Id: catalina.sh 609438 2008-01-06 22:14:28Z markt $
# -----------------------------------------------------------------------------
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m
-Xmx1536m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"
謝謝您的答覆。
謝謝菲利普Reichart。我在Catalina.sh中設置了我的JAVA_OPTS =「 - Djava.awt.headless = true -Dfile.encoding = UTF-8 ,但仍然不能正常工作 – 2012-07-06 10:25:01
如果您在Tomcat日誌中遇到異常,請添加堆棧跟蹤以及其他任何有關如何處理您的問題的信息(評論太少)。編輯'Catalina.sh'的相關部分可能也有幫助。 – 2012-07-06 11:42:35
感謝Philipp Reichart在設置 之後的工作。 headless = true 之前的另一個擴展Applet的類是在將此屬性設置爲true後給出問題,但現在我已經移除了applet依賴關係,並且它爲JFreeChart工作。 – 2013-02-28 07:45:29