This is not a new question, but Im help/clue less... so asking it here... Im getting the error "java.lang.ClassNotFoundException: org.apache.commons.digester.Rule" when Im trying to run a DynamicReport sample project. My specifications are below: Java - 1.7,commons-beanutils-1.9.3,commons-collections-3.2.2,commons-digester-3.2,commons-lang-3.7,commons-logging-1.2,dynamicreports-core-5.0.0,jasperreports-5.6,jasperreports-javaflow,
code snippet is below:
// import statements
public class sampleReport {
public sampleReport() {
build();
}
private void build() {
try {
JasperReportBuilder report = DynamicReports.report();
// a new report
report // create new report design
.columns(
// add columns title, field name data type
Columns.column("Item", "item",
DataTypes.stringType()),
Columns.column("Quantity", "quantity",
DataTypes.integerType()),
Columns.column("Unit price",
"unitprice",
DataTypes.bigDecimalType()))
.title(Components.text("Getting started report")
.setHorizontalAlignment(HorizontalAlignment.CENTER))
// shows report title
.pageFooter(Components.pageXofY())
// shows number of page at page footer
.setDataSource(createDataSource())
// set datasource
.show(); // create and show report
// show the report
report.show();
// export the report to a pdf file
report.toPdf(new FileOutputStream("c:/report.pdf"));
} catch (DRException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
private JRDataSource createDataSource() {
DRDataSource dataSource = new DRDataSource("item",
"quantity", "unitprice");
dataSource.add("Notebook", 1, new BigDecimal(500));
dataSource.add("DVD", 5, new BigDecimal(30));
dataSource.add("DVD", 1, new BigDecimal(28));
dataSource.add("DVD", 5, new BigDecimal(32));
dataSource.add("Book", 3, new BigDecimal(11));
dataSource.add("Book", 1, new BigDecimal(15));
dataSource.add("Book", 5, new BigDecimal(10));
dataSource.add("Book", 8, new BigDecimal(9));
return dataSource;
}
public static void main(String[] args) {
new sampleReport();
}
Any help is appreciated.
I am not aware of your IDE configuration and / or build configuration. However the error is pointing me into the direction of a jar version incompatibility issue. Basically what happens is that one of your jars is referencing a class that is not included in the current build path due to different version (older or newer)
Suggested Solution: If you have the capability of using a more advanced build tool like maven or gradle, it will automatically resolve the dependencies and can point out issues with the version. The best way to use them is to add the maven artifacts one by one (starting from the most complex-dependant jar) until all import errors are removed. This will probably fix all the version issues.
Alternative (FAST) Solution: download this version of apache.digester because if you look at the maven dependencies of jasper you can see that it references version 2.1 of digester whereas you are using version 3.2 which probably has the same class under a different package.
Hope it helps.