9

I'm developing some reports with Jaspersoft Studio.
I have a web app that should accept REST queries, and turn them into compiled reports.
So I have some of the JasperReports jars included:

  • groovy-all-2.0.1.jar
  • iText-2.1.7.js2.jar
  • jasperreports-5.2.0.jar

Problem is that when I compile my report and run from the Jaspersoft Studio, it works fine.
But when I compile and run it from my web app, it throws the exception:

net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : 
    Source text : CONCATENATE($V{startString}, "  -  ", $V{endString})
    at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:244)
    at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:591)
    at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:559)
...
Caused by: net.sf.jasperreports.engine.JRRuntimeException: Function CONCATENATE not found

When I change my CONCATENATE call in the report it works fine.

So this leaves me with a solution that I'm missing one of the JasperReports jars, but which one?

Alex K
  • 22,315
  • 19
  • 108
  • 236
csabee
  • 217
  • 2
  • 12

1 Answers1

13

You should also add jasperreports-functions-5.2.0.jar to your classpath.

This library contains net.sf.jasperreports.functions.standard.TextFunctions class with CONCATENATE function.

You can find this artifact at http://jaspersoft.artifactoryonline.com/jaspersoft/jr-ce-releases Maven repository.

The snippet from my test pom.xml:

<repositories>
    <repository>
        <id>jr-ce-releases</id>
        <url>http://jaspersoft.artifactoryonline.com/jaspersoft/jr-ce-releases</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>5.2.0</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>2.0.1</version>
    </dependency>
    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports-functions</artifactId>
        <version>5.2.0</version>
    </dependency>
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.1</version>
    </dependency>
</dependencies>

The net.sf.jasperreports.jasperreports-functions:5.2.0 artifact depends on joda-time.joda-time:2.1 artifact - you should also add to classpath the joda-time-2.1.jar


Notes:

You can find more information in Custom Functions in Report Expressions article

Alex K
  • 22,315
  • 19
  • 108
  • 236
  • 1
    From other recent experience: this question is also very relevant to the date-time functions as well. Maybe someone should try to link date-time function relation questions to this post as well. Trying to use TODAY() or NOW() in JasperStudio will yield the same result without adding these libraries to classpath. – Brandon S. May 19 '17 at 19:46
  • I had the same issue with the `MONTH()` function, this solution worked for me just adding `jasperreports-functions` and changing `groovy` to `groovy-all`. I don't know if this last was necesary, but my app is running smoothly. Thank you so much @AlexK – Alvaro Pedraza Aug 10 '17 at 23:09