While I am using a eclipse to run a file with "Run As" -> "Java
Application", it gives me the following error. Does anyone know what
the problem is?
<<The program>>:
/*
* Created on 2004-3-30
*/
import dori.jasper.engine.design.JasperDesign;
import dori.jasper.engine.JasperReport;
import dori.jasper.engine.JasperManager;
import dori.jasper.engine.JasperPrint;
import dori.jasper.engine.JRDataSource;
import dori.jasper.engine.data.JRBeanCollectionDataSource;
import dori.jasper.engine.JRException;
import dori.jasper.view.JasperViewer;
import dori.jasper.engine.JasperExportManager;
import java.util.Map;
import java.util.HashMap;
import java.util.Collection;
import java.util.Vector;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
/**
* @author Tony
*
*/
public class Y3Report {
private final static String PARAGRAPH =
"Received in apparent good order and condition"
+ "except as otherwise noted the total number or"
+ "containers or other package or units enumerated"
+ "below for transportation from the place of receipt to"
+ "the place of delivery subject to the terms hereof. One"
+ "of the signed Bill of Lading must be surrendered duly"
+ "endorsed in exchange for the Goods or delivery"
+ "order. On presentation of this document (duly"
+ "endorsed) to the Carrier by or on behalf of the Holder,"
+ "the rights and liabilities arising in accordance with the"
+ "terms hereof shall (without prejudice to any rule of"
+ "common law or statute rendering them binding"
+ "on the Merchant) become binding in all respects"
+ "between the Carrier and the Holder as though the"
+ "contract evidenced hereby had been made between"
+ "them.";
public static void main(String[] args) throws JRException {
// First, load JasperDesign from XML and compile it into
JasperReport
JasperDesign jrDesign =
JasperManager.loadXmlDesign("y3report.xml");
JasperReport jrReport = JasperManager.compileReport(jrDesign);
// Second, create a map of parameters to pass to the report.
Map parameters = new HashMap();
parameters.put("Paragraph", PARAGRAPH);
// Third, get a dataSource
JRDataSource jrDataSource =
new JRBeanCollectionDataSource(getBeanCollection());
// Fourth, create JasperPrint using fillReport() method
JasperPrint jasperPrint =
JasperManager.fillReport(jrReport, parameters, jrDataSource);
// You can use JasperPrint to create PDF
//JasperManager.printReportToPdfFile(jasperPrint, "y3report.pdf");
JasperExportManager.exportReportToHtmlFile(jasperPrint,
"y3report.pdf");
JasperExportManager.exportReportToHtmlFile(jasperPrint,
"y3report.html");
// Or to view report in the JasperViewer
JasperViewer.viewReport(jasperPrint);
}
private static Collection getBeanCollection() {
Collection c = new Vector();
try {
BufferedReader br = new BufferedReader(new
FileReader("DB.txt"));
String line;
while ((line = br.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line, "|");
DBBean dbBean = new DBBean();
dbBean.setShipper(st.nextToken());
dbBean.setConsignee(st.nextToken());
dbBean.setNotifyParty(st.nextToken());
dbBean.setOceanVNo(st.nextToken());
dbBean.setPlaceOfReceipt(st.nextToken());
dbBean.setPortOfLoading(st.nextToken());
dbBean.setPortOfDischarge(st.nextToken());
dbBean.setPortOfDelivery(st.nextToken());
dbBean.setNumberOfOriginal(st.nextToken());
dbBean.setMarksAndNumbers(st.nextToken());
dbBean.setNumberAndType(st.nextToken());
dbBean.setDescriptionOfGood(st.nextToken());
dbBean.setGrossWeight(st.nextToken());
dbBean.setMeasurementM3(st.nextToken());
c.add(dbBean);
}
} catch (IOException e) {
e.printStackTrace();
}
return c;
}
}
<<The error>>:
java.lang.NoClassDefFoundError: Y3Report
Exception in thread "main"
Georgy Pavlov - 07 Apr 2004 08:21 GMT
The only cause I could think of is that you haven't compiled the Y3Report
class before you tried to run it.
NoClassDefFound means that the java launcher cannot find the class . See
your bin (or whatever is your compile output directory) .
Is this the case?