Pergunta

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>
Foi útil?

Solução 2

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>

Outras dicas

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:

Also, see this similar q/a:

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top