Grails JFreeChart无法解析类:org.jfree.chart.ChartFactory

时间:2015-03-05 06:15:04

标签: grails groovy import jfreechart

我正在运行一个程序来使用JFreeChart库绘制折线图,​​然后Groovy / Grails结束。这是我的代码:

    package com.xyz.jfreechartdemo

    import org.jfree.chart.ChartFactory
    import org.jfree.chart.JFreeChart
    import org.jfree.chart.plot.PlotOrientation
    import org.jfree.data.category.DefaultCategoryDataset

    class JFreeChartSample {
      def getChart(){
      def dataset = createDataset()
      def chart = createChart(dataset)
      return chart
    }

    def createDataset() {
       DefaultCategoryDataset dataset = new DefaultCategoryDataset()
      dataset.addValue(2000,"X",1)
      dataset.addValue(3300,"X",2)
      dataset.addValue(2000,"X",3)
      dataset.addValue(3300,"X",4)
      return dataset
    }

   def createChart(dataset){
    JFreeChart chart = ChartFactory.createLineChart("Widget not rendered","X","Count",dataset,PlotOrientation.VERTICAL,false,true,false)
    return chart
  }
}

我正致力于IntelliJ Idea 13.1.3。编译成功。但这是我在运行程序时看到的内容:

Compilation error: startup failed:
C:\Users\User\IdeaProjects\JFreeChartDemo\grails app\domain\com\xyz\jfreechartdemo\JFreeChartSample.groovy: 3: unable to resolve class org.jfree.chart.ChartFactory
 @ line 3, column 1.
   import org.jfree.chart.ChartFactory
   ^

C:\Users\User\IdeaProjects\JFreeChartDemo\grails-app\domain\com\xyz\jfreechartdemo\JFreeChartSample.groovy: 6: unable to resolve class org.jfree.data.category.DefaultCategoryDataset
 @ line 6, column 1.
   import org.jfree.data.category.DefaultCategoryDataset
    ^

C:\Users\User\IdeaProjects\JFreeChartDemo\grails-app\domain\com\xyz\jfreechartdemo\JFreeChartSample.groovy: 5: unable to resolve class org.jfree.chart.plot.PlotOrientation
 @ line 5, column 1.
   import org.jfree.chart.plot.PlotOrientation
  ^

C:\Users\User\IdeaProjects\JFreeChartDemo\grails-app\domain\com\xyz\jfreechartdemo\JFreeChartSample.groovy: 4: unable to resolve class org.jfree.chart.JFreeChart
 @ line 4, column 1.
   import org.jfree.chart.JFreeChart
   ^

4 errors

我已将JCommon和所有JFreeChart库复制到lib文件夹中。我仍然看到这个错误。请帮忙。我是Groovy和Grails的新手。

1 个答案:

答案 0 :(得分:2)

添加代码的步骤:

  1. 添加您的jar依赖项,它将在BuildConfig.groovy中下载(您需要通过在线搜索您的jar版本,找到如何使用maven存储库下载它) http://mvnrepository.com/artifact/jfree/jfreechart
  2. 运行" grails clean"
  3. 运行" grails refresh-dependencies"