Compiling Jasper Reports with Maven2

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:

  1. Copied the installed plugin to my ‘project’ repository
  2. Renamed the directory, so it matched my own groupId, artifactId and version
  3. Edited the pom.xml and plugin.xml
  4. 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.

  5. Added our ‘project’ repository as a ‘plugin’ repository by modifying my settings.xml
  6. I added this to my settings.xml:

    <pluginRepositories>
        <pluginRepository>
          <id>local</id>
          <url>file://M:/maven_repo</url>
      </pluginRepository>
    </pluginRepositories>
    
  7. Modified the project’s pom.xml so my plugin version is used
  8. 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 😉

About Pascal Alma

Pascal is a senior IT consultant and has been working in IT since 1997. He is monitoring the latest development in new technologies (Mobile, Cloud, Big Data) closely and particularly interested in Java open source tool stacks, cloud related technologies like AWS and mobile development like building iOS apps with Swift. Specialties: Java/JEE/Spring Amazon AWS API/REST Big Data Continuous Delivery Swift/iOS
This entry was posted in Maven and tagged , . Bookmark the permalink.

3 Responses to Compiling Jasper Reports with Maven2

  1. Alfred Chan says:

    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

  2. Pascal Alma says:

    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.

  3. Jon Bråten says:

    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.

Comments are closed.