Problem running on Websphere server on Unix platform

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
monaweb
Posts: 6
Joined: Mon May 05, 2008 9:47 pm

Problem running on Websphere server on Unix platform

Post by monaweb » Mon May 05, 2008 9:59 pm

I downloaded the jfreechart-1.0.9.jar and included in my project. It works fine on my PC's test server, also works fine on the websphere server on a windows server. When I deployed the same application to websphere on an AIX/UNIX server, I got error when running a web report calling Jfreechart class.

[Servlet Error]-[org/jfree/chart/axis/CategoryAxis]: java.lang.NoClassDefFoundError: org/jfree/chart/axis/CategoryAxis
at org.jfree.chart.ChartFactory.createBarChart(ChartFactory.java:794)

A call from ChartFactory.createBarChart function to CategoryAxis class fails with NoClassDefFoundError. I checked and the class is out there in place. What can I do to make it work. It is clueless as everything looks in place. Download page states that both version of jar files are platform independent. Why is it working on windows server not Unix? Thank.

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Mon May 05, 2008 10:35 pm

Is jfreechart-1.0.9.jar specified on your CLASSPATH?
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

monaweb
Posts: 6
Joined: Mon May 05, 2008 9:47 pm

Post by monaweb » Tue May 06, 2008 12:17 am

No. The jar is not in the path. The problem is the call fails when one Jfreechart class calls another class within the jar. If the path is missing it should not enter the caller at first. The jar file is included in the lib directory within the web app deployed. All other jar files included in this lib path are called with no problem. They are not included in classpath either. Thanks for replying. Can you explain why this particular one needs to be there and why the first call to ChartFactory.createBarChart from my code didn't fail?

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Tue May 06, 2008 12:23 am

monaweb wrote:Can you explain why this particular one needs to be there and why the first call to ChartFactory.createBarChart from my code didn't fail?
The typical reason why people would get NoClassDefFoundError exceptions is that they forget to put the JFreeChart jar on their environment's CLASSPATH variable. It appears that your web app deployment's lib directory must handle the classpath automagically. I have no clue why you would only see the error on the second call to ChartFactory.createBarChart unless there is some weird server side behavior that I am unawear of. I do not do any web development with Java, so I have reached the limits of my knowledge in this area.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

monaweb
Posts: 6
Joined: Mon May 05, 2008 9:47 pm

Post by monaweb » Tue May 06, 2008 2:26 am

How do I add this to CLASSPATH? Thanks.

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Tue May 06, 2008 11:44 am

If you are in a web-application and all the jars are in the WEB-INF/lib directory, then they are added on the classpath automatically.

However, your error might result from a simple Headless-Exception or a related problem.

You are running your application on a server that has no X11 installed and no X11-Server running. The server runs fine until you try to access the charting (which uses the AWT which is not available as you have no X11 server and probably did not activate the Headless mode).

Enable the headless mode (if you are running JDK 1.4 or later, else you have troubles now) and your no-classdef-found-error should go away.

(The NoClassDefFoundError is thrown when a dependency for a class cannot be loaded. The dependency can be another class or can be a native library. Therefore this error does not necessarily indicate a ClassPath problem. Thanks Sun for messing up a otherwise clear exception :))

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue May 06, 2008 12:57 pm

Taqua wrote:(The NoClassDefFoundError is thrown when a dependency for a class cannot be loaded. The dependency can be another class or can be a native library. Therefore this error does not necessarily indicate a ClassPath problem. Thanks Sun for messing up a otherwise clear exception :))
Maybe we should try to submit a patch (to OpenJDK) that makes the exception more clear? I'm short on time at the moment, though, unfortunately.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

monaweb
Posts: 6
Joined: Mon May 05, 2008 9:47 pm

Post by monaweb » Tue May 06, 2008 3:32 pm

How do I enable headless mode? Thanks.

zhanghb
Posts: 2
Joined: Wed May 07, 2008 3:31 am

Post by zhanghb » Wed May 07, 2008 6:17 am

monaweb wrote:How do I enable headless mode? Thanks.
You can enable the x11 on unix server,
$ X -vfb -force :1 &
OR
$ /bin/nohup X -vfb -force :1 1>/dev/null 2>/dev/null &
do following before start application server:
$ export DISPLAY=<hostname>:1

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed May 07, 2008 8:02 am

monaweb wrote:How do I enable headless mode? Thanks.
See item 10 in the FAQ:

http://www.jfree.org/jfreechart/faq.html#FAQ10
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

monaweb
Posts: 6
Joined: Mon May 05, 2008 9:47 pm

Post by monaweb » Sat May 10, 2008 2:51 am

I read the discussions and added

System.setProperty("java.awt.headless", "true");

at the first line of doGet() function of the servlet. Compiled with J2RE1.4.2_01 and ran on WebSphere5 on AIX5.2. The error message changed to

[Servlet Error]-[Can't connect to X11 window server using '155.179.85.43:0.0' as the value of the DISPLAY variable.]: java.lang.InternalError: Can't connect to X11 window server using '155.179.85.43:0.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:175)
at java.lang.Class.forName1(Native Method)
at java.lang.Class.forName(Class.java(Compiled Code))
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:91)
at java.awt.Font.initializeFont(Font.java:333)
at java.awt.Font.<init>(Font.java:368)
at org.jfree.chart.axis.Axis.<clinit>(Axis.java:130)
at org.jfree.chart.ChartFactory.createBarChart(ChartFactory.java:794)

instead of NoClassFound error.

Do I have to get the system admin involved to force xvfb?

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Sat May 10, 2008 12:28 pm

No, but the headless mode must be activated before any of the AWT classes are loaded. When you try to set the property in the same servlet that also uses JFreeChart, then the classes are already loaded (as on loading the servlet, all dependent classes are loaded as well. Servlet references JFreeChart and JFreeChart references AWT).

The only safe way to do this, is to set the system property during the server startup (means: Add a "-Djava.awt.headless=true" to your java commandline arguments or the server's global configuraiton).

monaweb
Posts: 6
Joined: Mon May 05, 2008 9:47 pm

Post by monaweb » Tue May 13, 2008 2:47 am

Added -Djava.awt.headless=true and it works! Thank you very much for help.

Roman Tarasov
Posts: 1
Joined: Wed Oct 22, 2008 7:27 pm

Post by Roman Tarasov » Wed Oct 22, 2008 7:40 pm

I found this topic useful in my absolutely similar situation. But didn't understand how to set that property "-Djava.awt.headless=true". Should I change startServer.sh and add there "-Djava.awt.headless=true"?
How the server's global configuration is set otherwise?

Locked