Search code examples
javaintellij-ideajavafxjasper-reportsopenjdk-11

How to use Jasper Reports in IntelliJ IDEA with OpenJDK11


So I've been using Jasper Reports on JDK8 (Netbeans 11.1 & JavaFX 2) and everything was simple. Now I am migrating from JDK8 to OpenJDK11 with gradle (IntelliJ IDEA & JavaFX 14) and I am stuck with Jasper Reports. I tried to add the dependency compile 'net.sf.jasperreports:jasperreports:6.12.2' and the jar files were downloaded successfully, but when I go to my code and try to import the necessary libraries I can't find them.

Here's the code I was using in JDK8 (which I think should be the same in OpenJDK11) :

@FXML
public void print(ActionEvent actionEvent) {
        // My report
        JasperReport jreport = JasperCompileManager.compileReport("path\\to\\my\\report\\newReport.jrxml");

        // The data source to use to create the report
        JRBeanCollectionDataSource jcs = new JRBeanCollectionDataSource(list);
        JasperPrint jprint = JasperFillManager.fillReport(jreport, null, jcs);

        // Viewing the report
        JasperViewer.viewReport(jprint, false);
    }

and here's the libraries I need (net.sf was not detected at all eventhought the jar file is downloaded):

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.view.JasperViewer;

Solution

  • So after some research and many new problems, I think I've found a simple solution:

    1. Add this dependencies to your gradle project (and build it):
    implementation 'net.sf.jasperreports:jasperreports:6.12.2'
    implementation 'net.sf.jasperreports:jasperreports-fonts:6.12.2'
    
    1. In module-info.java add requires jasperreports;
    2. If you run your project, an exception about iText2.1.7 will appear, so what you need to do is add this this dependency implementation 'com.lowagie:itext:2.1.7'
    3. Rebuild yur project and Voilà! everything should be working fine. (don't forget to import the libraries when coding :D)

    I hope it helped someone besides me!