I am trying to use Jasper using the jasperreports-maven-plugin.
So you create your .jrxml in a directory src/main/jasperreports and the plugin compiles it and creates a .jasper file in target/jasper. So far this is working.
Now I would like to read this .jasper file into a Java class in order to fill the report. This is where my problem is. How do I access this .jasper file from target/jasper?
I thought I needed to add it as additional resource directory in my pom.xml:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>target/jasper</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<configuration>
<outputDirectory>${project.build.directory}/jasper</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile-reports</goal>
</goals>
</execution>
</executions>
...
And then get it using getResource like this:
URL resource = getClass().getResource("/target/jasper/DataSourceReport.jasper");
However, this returns null. The file DataSourceReport.jasper is inside my project under target/jasper, but it seems to be unable to find it.
Can anyone tell me what I'm doing wrong or why this isn't working?