我試圖用Eclipse Neon JAVA EE IDE使用Jaspersoft studio 6.4.0運行空白的Jasperreport(空白A4.Jrxml)。每次運行這段代碼時,我都會被要求添加一個jasper jar依賴文件。於是我將Jasper庫和Jasper jar文件下載到我的Java程序(JasperClass.java)中並保存在lib文件夾中。但我仍然收到錯誤添加jar文件。我研究了棧流以前的解決方案,但仍然無法解決它。請幫助我。運行java代碼時自動生成空白碧玉報告的錯誤
JAR庫lib文件夾:https://imgur.com/Nj1FOGk
錯誤:
Oct 11, 2017 1:01:28 PM net.sf.jasperreports.extensions.DefaultExtensionsRegistry loadRegistries
WARNING: Extension resource jar:file:/C:/repo/JasperTest/lib/jasperreports-javaflow-6.4.0.jar!/jasperreports_extension.properties was found to be a duplicate of jar:file:/C:/repo/JasperTest/lib/jasperreports-6.4.0.jar!/jasperreports_extension.properties in classloader [email protected]
Exception in thread "main" java.lang.NoClassDefFoundError: com/lowagie/text/DocumentException
at net.sf.jasperreports.engine.JasperExportManager.exportToPdfFile(JasperExportManager.java:150)
at net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfFile(JasperExportManager.java:503)
at JasperPackage.JasperClass.main(JasperClass.java:45)
Caused by: java.lang.ClassNotFoundException: com.lowagie.text.DocumentException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
的Java Class.Java
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
public class JasperClass {
public static void main(String[] args) throws JRException, IOException {
// Compile jrxml file.
JasperReport jasperReport = JasperCompileManager
.compileReport("C:/repo/JasperTest/Blank_A4.jrxml");
// Parameters for report
Map<String, Object> parameters = new HashMap<String, Object>();
// DataSource
// This is simple example, no database.
// then using empty datasource.
JRDataSource dataSource = new JREmptyDataSource();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
parameters, dataSource);
// Make sure the output directory exists.
File outDir = new File("C:/repo/JasperTest");
outDir.mkdirs();
// Export to PDF.
JasperExportManager.exportReportToPdfFile(jasperPrint,
"C:/repo/JasperTest/Blank.pdf");
System.out.println("Done!");
}
}
空白A4.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.0.final using JasperReports Library version 6.4.1 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="1b2e21df-4dba-46a0-8e2e-1bed8b81853e">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<queryString>
<![CDATA[]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch"/>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
比你的迴應。我不想兩個罐子。我試圖從lib文件夾中刪除jasperreports-6.4.0.jar。但是我添加了一個新的異常來添加已經存在的javaflow jar文件。請查看圖像。圖片:[鏈接](https://imgur.com/iWN5VZI)。 '在線程中的異常「main」java.lang.NoClassDefFoundError:org/apache/commons/javaflow/bytecode /可繼續 \t at java.lang.ClassLoader.defineClass1(Native Method) \t at java.lang.ClassLoader.defineClass(Unknown源) – saleem
當我試圖刪除Javaflow jar而不是Jasperreport jar。我正在低於錯誤。 '線程中的異常「main」java.lang.NoClassDefFoundError:com/lowagie/text/DocumentException \t at net.sf.jasperreports.engine.JasperExportManager.exportToPdfFile(JasperExportManager.java:150)' – saleem