Search code examples
javajasper-reports

No query executer factory registered for the 'sql' language


The issue regarding the error: net.sf.jasperreports.engine.JRRuntimeException: No query executer factory registered for the 'sql' language

My issue is: whenever I try to run JasperReports from dev environment I can get the reports generated. But when I run jar file the error comes up.

Is there any workaround to set the enironment variable net.sf.jasperreports.query.executer.factory.sql ? I try to use Jasper 6.19.1 and 6.20.0 but the problem us the same.

The problem is related to this variable located in the file default.jasperreports.properties that's located in the JasperReports jar root.

I'm using IntelliJ Ide and gradle

I created a program to show the problem. There are only two files.

Main.java

package br.com.mawan.mawanReport;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

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.view.JasperViewer;

public class Main {

    private static final String url = "jdbc:mysql://localhost:3306/wavecounter";
    private static final String driver = "com.mysql.cj.jdbc.Driver";
    private static final String login = "root";
    private static final String pwd = "";

    public Main() {}

    public void print(String path ) throws JRException, SQLException, ClassNotFoundException {
        Class.forName(driver);
        Connection conn = DriverManager.getConnection(url, login, pwd);
        JasperReport report = JasperCompileManager.compileReport( path );
        JasperPrint reportFill = JasperFillManager.fillReport( report , null, conn );
        JasperViewer.viewReport( reportFill , true );
        conn.close();
    }

    public static void main(String[] args) {
        try {
            new br.com.mawan.mawanReport.Main().print( "C:\\wavecounter\\reports\\Teste.jrxml" );
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

build.gradle

plugins {
    id 'java'
}

group 'br.com.mawan'
version '1.0.0'

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    implementation("org.apache.poi:poi:5.2.2")
    implementation("com.lowagie:itext:2.1.7")
    implementation("org.olap4j:olap4j:1.2.0")
    implementation("net.sf.jasperreports:jasperreports:5.6.1")
    implementation("net.sf.jasperreports:jasperreports-fonts:5.6.1")
    implementation("xerces:xercesImpl:2.10.0")
    implementation("mysql:mysql-connector-java:8.0.29")
}

jar {
    manifest { attributes "Main-Class": "br.com.mawan.mawanReport.Main" }
    from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
    exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}

Solution

  • To solve it I created a file concatenating both files and put it in the resource with the name new.jasperreports_extension.properties.

    Inside the jar tag I inserted the file name in exclude command. After that a insert a command to rename new.jasperreports_extension.properties to jasperreports_extension.properties.

    jar {
        exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA','jasperreports_extension.properties'
        manifest { attributes "Main-Class": "br.com.mawan.mawanReport.Main" }
        from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
        rename('new.jasperreports_extension.properties', "jasperreports_extension.properties")
    }
    

    After that everything worked.

    I would like to give credit to dada67.