java.lang.NoClassDefFoundError JasperReport

0

I'm working with JasperReport from your IReport plugin.

I have already designed all my form from this plugin but at the moment of running my application it gives me the following exception:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/beanutils/PropertyUtils
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:111)
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:96)
at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue(JRBeanCollectionDataSource.java:100)
at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:1331)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1232)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1208)
at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1577)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:149)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:932)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:864)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:88)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:969)
at REPORTE.FacturaReporte.crearPDF(FacturaReporte.java:51)

The code trying to open the JasperReport is the following:

public void crearPDF(Factura miFactura, Cliente unCliente) throws JRException {
    //Creo mi lista con los parametros a enviar
    Map misParametros = new HashMap();

    misParametros.put("codigoFactura", miFactura.getCodigo());
    misParametros.put("fechaFactura", new SimpleDateFormat("dd-MM-yyyy").format(miFactura.getFecha().getTime()));
    misParametros.put("dniCliente", unCliente.getDni());
    misParametros.put("nombreCliente", unCliente.getMisDatosPersonales().getNombre());
    misParametros.put("apellidoCliente", unCliente.getMisDatosPersonales().getApellido());
    misParametros.put("telefonoCliente", unCliente.getMisDatosPersonales().getTelefono());

    //Creo la variable que contendrá el reporte
    JasperReport miReporte = (JasperReport) JRLoader.loadObjectFromFile("src/REPORTE/Factura.jasper");

    // Definimos cual sera nuestra fuente de datos
    JRBeanCollectionDataSource datos = new JRBeanCollectionDataSource(miFactura.getRenglones());

    //Preparo para mostrar
    JasperPrint miJasperPrint = JasperFillManager.fillReport(miReporte, misParametros ,datos);

    JasperViewer miJasperViewer = new JasperViewer(miJasperPrint, false);

    //Le doy un titulo al documento
    miJasperViewer.setTitle("Factura "+ miFactura.getCodigo() +"");

    //Lo hago visible
    miJasperViewer.setVisible(true);
}

As you may have already noticed, the problem is detected in the following line:

//Preparo para mostrar
    JasperPrint miJasperPrint = JasperFillManager.fillReport(miReporte, misParametros ,datos);

I suspect that you are referring to a problem with a JAR / Library or something like that. Would you give me any help?

    
asked by Ramiro Romero 11.06.2018 в 23:17
source

1 answer

1
  

java.lang.NoClassDefFoundError: x / y / z / ClassName

means that the program uses a x.y.z.NombreClase class that is not in the classpath.

In this case, it is org.apache.commons.beanutils.PropertyUtils

Doing a search for org.apache.commons.beanutils.PropertyUtils jar takes us to Apache Commons BeanUtils .

Now it's about finding out what version you need the JasperReport (it will depend on the version you use, in the documentation or in the Maven repository it will list the dependencies), download the jar and include it in the classpath at the time of Run the program.

Although at first it may seem complicated, using a dependency manager such as Maven or Ivy solves these problems in a transparent way.

    
answered by 11.06.2018 / 23:25
source