javamavenjasper-reportsmaven-pluginjasper-plugin

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>

Solution

  • This is how I solved the issue. Adding phase

             <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jasperreports-maven-plugin</artifactId>
                <executions>
                 <execution>
                      <phase>compile</phase>
                      <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>