Recently I encountered following exception when using JFreeChart to generate a graphical chart in a product deployed in a weblogic server.
Reason:
During the issue investigation, I found out that the above mentioned Weblogic server is located inside a headless server. (A headless server is a server which does not have a monitor, a key board and a mouse. The control and access to a headless server is done using a network card (remote connection).) It turned out the reason for the above exception is that.
The problem happens because JFreeChart class has some static variables which are initialized using local graphic environment properties retrieved from javax.swing.UIManager.
javax.swing.UIManager in turn tries to get these default properties from local graphic environment.
But because there is no graphic environment in a headless server , initializing sun.awt.X11GraphicsEnvironment class (local graphic environment class) fails and then the loading of JFreeChart class also fails.
Solution:
The solution for this problem is to add -Djava.awt.headless=true to the list of server start arguments of the managed server. You can change it by,
Read more about Java headless mode from: http://www.oracle.com/technetwork/articles/javase/headless-136834.html
]] Root cause of ServletException. java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68) at sun.awt.X11.XToolkit.
(XToolkit.java:89) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at java.awt.Toolkit$2.run(Toolkit.java:834) at java.security.AccessController.doPrivileged(Native Method) at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:826) at sun.swing.SwingUtilities2$AATextInfo.getAATextInfo(SwingUtilities2.java:126) at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults(MetalLookAndFeel.java:1556) at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults(BasicLookAndFeel.java:130) at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults(MetalLookAndFeel.java:1591) at javax.swing.UIManager.setLookAndFeel(UIManager.java:541) at javax.swing.UIManager.setLookAndFeel(UIManager.java:581) at javax.swing.UIManager.initializeDefaultLAF(UIManager.java:1343) at javax.swing.UIManager.initialize(UIManager.java:1432) at javax.swing.UIManager.maybeInitialize(UIManager.java:1420) at javax.swing.UIManager.getDefaults(UIManager.java:660) at javax.swing.UIManager.getColor(UIManager.java:702) at org.jfree.chart.JFreeChart. (JFreeChart.java:261) at org.jfree.chart.ChartFactory.createTimeSeriesChart(ChartFactory.java:1918)
Reason:
During the issue investigation, I found out that the above mentioned Weblogic server is located inside a headless server. (A headless server is a server which does not have a monitor, a key board and a mouse. The control and access to a headless server is done using a network card (remote connection).) It turned out the reason for the above exception is that.
The problem happens because JFreeChart class has some static variables which are initialized using local graphic environment properties retrieved from javax.swing.UIManager.
javax.swing.UIManager in turn tries to get these default properties from local graphic environment.
But because there is no graphic environment in a headless server , initializing sun.awt.X11GraphicsEnvironment class (local graphic environment class) fails and then the loading of JFreeChart class also fails.
Solution:
The solution for this problem is to add -Djava.awt.headless=true to the list of server start arguments of the managed server. You can change it by,
- Login to the Weblogic admin console.
- Expand Environment and select Servers.
- In the Servers table, click the name of the managed server you want to configure.
- Select Configuration > Server Start.
Read more about Java headless mode from: http://www.oracle.com/technetwork/articles/javase/headless-136834.html
No comments:
Post a Comment