Like I posted before I am currently working on the transition from Ant to Maven to build and package our application. One of the tasks that is performed by Ant is compiling the Jasper Reports (from the .jrxml files to the .jasper ones). Of course there is a plugin for this task: the jasperreports-maven-plugin.
You can use the plugin by adding this to the project’s pom.xml for the plugin:
<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jasperreports-maven-plugin</artifactId> <version>1.0</version> <configuration> <outputDirectory>src/main/jasperreports/compiled</outputDirectory> <xmlValidation>true</xmlValidation> </configuration> <executions> <execution> <goals> <goal>compile-reports</goal> </goals> <phase>compile</phase> </execution> </executions> </plugin> </plugins> </build>
And add the Jasper Reports dependency like this:
<dependency> <groupId>jasperreports</groupId> <artifactId>jasperreports</artifactId> <version>3.0.0</version> </dependency>
After adding these pieces to the pom, you can run it with the following command:
mvn clean jasperreports:compile-reports
So far nothing special, I guess. Until I saw the output of the Maven compile target:
Error compiling report design : D:\m2_workspace\my-project\src\main\jasperreports\Statist
icsMessageCountAll.jrxml : Element type “hyperlinkTooltipExpression” must be declared.
[INFO] ————————————————————————
[INFO] For more information, run Maven with the -e switch
[INFO] ————————————————————————
[INFO] Total time: 17 seconds
[INFO] Finished at: Tue Jun 24 10:03:21 CEST 2008
[INFO] Final Memory: 8M/14M
[INFO] ————————————————————————
After quite some time I found out the error occurred because the plugin uses the Jasper Report version 1.2.0 and this version has an other DTD then all newer versions… So now I knew the cause, but how to solve this???
Well, the way I did it was by the following steps:
- Copied the installed plugin to my ‘project’ repository
- Renamed the directory, so it matched my own groupId, artifactId and version
- Edited the pom.xml and plugin.xml
- Added our ‘project’ repository as a ‘plugin’ repository by modifying my settings.xml
- Modified the project’s pom.xml so my plugin version is used
In the copied plugin sources I made the references in the pom.xml and plugin.xml match my groupId, artifactId and version and made sure JasperReports 3.0.0 is used.
I added this to my settings.xml:
<pluginRepositories> <pluginRepository> <id>local</id> <url>file://M:/maven_repo</url> </pluginRepository> </pluginRepositories>
The last step is to make sure my version of the plugin is used and not the default JasperReports plugin.
<plugin> <groupId>net.pascalalma</groupId> <artifactId>new-jasperreports-maven-plugin</artifactId> <version>1.0</version> <configuration> <outputDirectory>${project.build.directory}/jasper</outputDirectory> <xmlValidation>true</xmlValidation> </configuration> <executions> <execution> <goals> <goal>compile-reports</goal> </goals> </execution> </executions> </plugin>
When this is all in place I can now compile the reports with the command:
mvn clean net.pascalalma:new-jasperreports-maven-plugin:1.0:compile-reports
.
Although this is working fine, I am still having some questions about this. First question is if this is the way to do something like this, because it is quite some work to do and when a new version of the plugin is available I will have to copy these again…Doesn’t feel right.
Second question I had is why the short notation of the command does not work (like explained here):
mvn clean new-jasperreports:compile-reports
I can’t get this working, so I guess I have some things to do in the near future 😉
Hi Pascal,
You can add additional dependencies in the jasperreport plugin, so that maven can make use of jasperreport version 3.0 to compile.
Alfred
org.codehaus.mojo
jasperreports-maven-plugin
jasperreports
jasperreports
3.0.0
compile-reports
Hi Alfred,
Thx for your comment. I must say I had tried that one, because that is of course a lot easier then the story in my post. But for som ereason it didn’t work for me and so I had to go the way I described.
But whenever I run into this again (I have left the project now) I will take some more time to check this, but if I recall correctly I found more issues on the internet with your proposed solution.
You can override the version of a plugin’s dependency, by adding this to the section of the JR-plugin in your pom.xml:
jasperreports
jasperreports
2.0.2
Note that you need maven 2.0.9 for this feature.