我想打印存储在数据库中的数据,我使用了ireport和jasperreport,我认为我的库有问题,这里是我下载的库列表:
jasperreports-6.0.4.jar
jasperreports-font-6.0.4.jar
jasperreports-javaflow-6.0.4.jar
barecode4j-2.1.jar
commons-beanutils-1.9.0.jar
commons-codec-1.5.jar
commons-collections-3.2.1.jar
commons-digester-2.1.jar
commons-logging-1.1.1.jar
iText-2.1.7.js2.jar
com-jaspersoft-ireport.jar
data.html
<form action="Print">
<input type="submit" value="print">
</form>
的Servlet:Print.java
private static Connection con;
PrintWriter out = response.getWriter();
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
}catch(SQLException e){
e.printStackTrace();
}
catch(ClassNotFoundException f){
f.printStackTrace();
}
try{
JasperDesign jd= JRXmlLoader.load("list_user.jrxml");
String sql ="select * from user";
JRDesignQuery newQuery=new JRDesignQuery();
newQuery.setText(sql);
jd.setQuery(newQuery);
JasperReport jasperReport =JasperCompileManager.compileReport(jd);
JasperPrint jasperprint=JasperFillManager.fillReport(jasperReport,null,con);
JasperViewer.viewReport(jasperprint);
}catch(Exception e){
System.out.println(e);
}
我遇到了这个错误:
java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:344)
at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java:156)
at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:114)
at net.sf.jasperreports.engine.JasperCompileManager.getCompiler(JasperCompileManager.java:869)
at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:357)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:617)