Could not initialize class org.jfree.chart.JFreeCh

2019-08-14 00:56发布

问题:

EDIT:

Hi there i am using JBoss 7.1 Runtime Server and i have an Problem on my MAC when i build my Project and run it on localhost i get always an ERROR from the JFreeChart Library that it could not initialize. I'm using Maven to import all my Library's my repository's was:

<repositories>
        <repository>
            <id>java.net2</id>
            <name>Repository hosting the jee6 artifacts</name>
            <url>http://download.java.net/maven/2</url>
        </repository>
        <repository>
            <id>JBoss repository</id>
            <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
        </repository>

        <repository>
            <id>org.openfaces</id>
            <url>http://repository.openfaces.org/repository</url>
        </repository>
        <repository>
            <id>jfree</id>
            <url>http://www.ibiblio.org/maven/jfree/</url>
        </repository>
    </repositories>

and the dependency what i use for JFreeChart was:

        <dependency>
            <groupId>jfree</groupId>
            <artifactId>jcommon</artifactId>
            <version>1.0.16</version>
        </dependency>

        <dependency>
            <groupId>jfree</groupId>
            <artifactId>jfreechart</artifactId>
            <version>1.0.13</version>
        </dependency>

Here is the ERROR:

exception

javax.servlet.ServletException: Could not initialize class org.jfree.chart.JFreeChart
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
root cause

java.lang.NoClassDefFoundError: Could not initialize class org.jfree.chart.JFreeChart
    java.lang.Class.forName0(Native Method)
    java.lang.Class.forName(Class.java:171)
    org.openfaces.taglib.internal.chart.AbstractStyledComponentTag.checkJFreeChart(AbstractStyledComponentTag.java:33)
    org.openfaces.taglib.internal.chart.AbstractStyledComponentTag.setComponentProperties(AbstractStyledComponentTag.java:27)
    org.openfaces.taglib.internal.chart.ChartTag.setComponentProperties(ChartTag.java:39)
    org.openfaces.taglib.facelets.AbstractFaceletsComponentHandler.setAttributes(AbstractFaceletsComponentHandler.java:54)

When i Run my Project on a Windows PC localhost or on a Linux Server i didn't get this ERROR. I hope someone can help me and give me a solution for my Problem.

回答1:

Please ensure you have your JAR in WEB-INF/lib folder. If your are using Apache Maven kindly include the following dependency in pom.xml

<dependency>
    <groupId>jfree</groupId>
    <artifactId>jfreechart</artifactId>
    <version>1.0.13</version>
</dependency>


回答2:

I guess you're running on a headless environment so UI (awt) doesn't work, so pass -Djava.awt.headless=true to make it work