Eclipse RCP with JFreeChart

I am trying to use JFreeChart in an RCP application with a simple view. I added the Jar JfreeChart file as a reference for the library.

Unable to create view due to error:

Could not create the view: Plug-in "ViewJFreeChart" was unable to instantiate class "viewJFreeChart.View". java.lang.NoClassDefFoundError: org/jfree/data/general/PieDataset at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Unknown Source) at java.lang.Class.getConstructor0(Unknown Source) at java.lang.Class.newInstance0(Unknown Source) at java.lang.Class.newInstance(Unknown Source) 

......

This is the source code for View.java:

 package viewJFreeChart; import java.awt.Font; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PiePlot; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; import org.jfree.experimental.chart.swt.ChartComposite; public class View extends ViewPart { public static final String ID = "ViewJFreeChart.view"; private TableViewer viewer; /** * This is a callback that will allow us to create the viewer and initialize * it. */ public void createPartControl(Composite parent) { JFreeChart chart = createChart(createDataset()); final ChartComposite frame = new ChartComposite(parent, SWT.NONE, chart, true); } /** * Passing the focus request to the viewer control. */ public void setFocus() { viewer.getControl().setFocus(); } /** * Creates the Dataset for the Pie chart */ private PieDataset createDataset() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("One", new Double(43.2)); dataset.setValue("Two", new Double(10.0)); dataset.setValue("Three", new Double(27.5)); dataset.setValue("Four", new Double(17.5)); dataset.setValue("Five", new Double(11.0)); dataset.setValue("Six", new Double(19.4)); return dataset; } /** * Creates the Chart based on a dataset */ private JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 1", // chart // title dataset, // data true, // include legend true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionOutlinesVisible(false); plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plot.setNoDataMessage("No data available"); plot.setCircular(false); plot.setLabelGap(0.02); return chart; } } 
+6
java eclipse-plugin jfreechart
source share
1 answer

When you say that you added the dependency as a reference library, I assume that you mean that you added it as a jar dependency to the Eclipse project through the Java Build Path section of the project properties, this will only work for compilation in your workspace. RCP needs dependencies / nested banks, which must be defined in the manifest in order for them to be resolved on the target platform.

To install the plugin dependency, open the manifest file, you will see an editor with several tabs. Select the Dependencies tab and click Add ... , select the plugin and click OK.

dependencies tab screenshot

If you want to link the jar in your plugin, you need to add it to the Manifest class path. Suppose the jar is in a subdirectory of your plugin project, select the Runtime tab of the Manifest editor, then select the Classpath section Add .... Add the jar and OK.

+7
source share

All Articles