这不是一个新问题,但是我的帮助/线索较少...所以在这里询问...我在尝试运行以下命令时收到错误“ java.lang.ClassNotFoundException:org.apache.commons.digester.Rule” DynamicReport示例项目。我的规格如下: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,
代码段如下:
// 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();
}
任何帮助表示赞赏。
我不知道您的IDE配置和/或构建配置。但是,错误使我进入了jar版本不兼容问题的方向。基本上发生的事情是您的一个jar引用了由于版本不同(旧版本或更新版本)而未包含在当前构建路径中的类
建议的解决方案:如果您能够使用maven或gradle之类的更高级的构建工具,它将自动解决依赖关系并指出版本问题。最好的使用方式是逐个添加Maven工件(从最复杂的jar开始),直到消除所有导入错误为止。这可能会解决所有版本问题。
替代(FAST)解决方案:下载此版本的apache.digester,因为如果您查看jasper的Maven依赖项,则可以看到它引用了2.1版的摘要,而您正在使用的3.2版在不同的软件包下可能具有相同的类。
希望能帮助到你。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句