Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing custom classes in jrxml and compiling with maven plugin

I have to import few custom Java classes in JasperReports's JRXML file.
I am able to do that using

<import value="org.ga.jasper.sample.MyCustomClass"/>

This works perfectly fine and I am able to run this jrxml and test my code.

Problem comes when I want to precompile this into .jasper file by using jasperreports-maven-plugin.

When doing a build, it complains saying it does not find my package and hence import is invalid.

package org.ga.jasper.sample does not exist
import org.ga.jasper.sample.MyCustomClass;

FYI, My Java code and .jrxml are in the same maven module but in different folders.

Following is the code from my plugin tag

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jasperreports-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>compile-reports</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <sourceDirectory>src/main/resources/jasper</sourceDirectory>
        <outputDirectory>${project.build.directory}/jasper</outputDirectory>
        <compiler>net.sf.jasperreports.engine.design.JRJavacCompiler</compiler>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>4.5.1</version>
        </dependency>
    </dependencies>
</plugin>
like image 225
ga78 Avatar asked Nov 26 '25 02:11

ga78


1 Answers

By default, the plugin runs in the generate-resources phase, before the current module's classes have been compiled. You can change the plugin to run at the compile phase instead. See notes at bottom of page here:

  • http://mojo.codehaus.org/jasperreports-maven-plugin/usage.html

Also, see this similar q/a:

  • Compile JasperReports jrxml with scriptlet dependency in same project via Maven
like image 130
kaliatech Avatar answered Nov 28 '25 14:11

kaliatech



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!