Days function working in Jaspersoft Studio but not with ReportServer

0

Hello everybody!

I hace few reports which are using the function DAYS(DATE1, DATE2) to calculate number of days between two dates.

My expression is (DAYS(new SimpleDateFormat("dd/MM/yyyy").parse($F{DATE_DEBUT_ABSENCE}),new SimpleDateFormat("dd/MM/yyyy").parse($V{date_fin_sejour}))+1).

It's working well and without error on Jaspersoft studio 6.4.0 but when i try to generate a report with jasperreports 6.2.0 i have an error.

net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: (DAYS(new SimpleDateFormat("dd/MM/yyyy").parse($F{DATE_DEBUT_ABSENCE}),new SimpleDateFormat("dd/MM/yyyy").parse($V{date_fin_sejour}))+1)

How an expression can work on Jaspersoft Studio and not on jasperreports? Thanks in advance for your future answer.

siick's picture
24
Joined: Jul 3 2017 - 8:35am
Last seen: 1 year 7 months ago

5 Answers:

1

I got it to be working after adding dependency jars to the build path. 

You need jasperreports functions and joda time jars for it to be working. both the jars can be found below.

https://sourceforge.net/projects/jasperreports/files/jasperreports/Jaspe...

https://github.com/JodaOrg/joda-time/releases/download/v2.9.9/joda-time-...

reportdev's picture
1226
Joined: Oct 12 2015 - 12:05pm
Last seen: 2 months 3 weeks ago
0

Hi there,

just a quick info. Even I got the same error when used on jasperreports api, but it works fine on Jasper Server and Studio.

I believe jasperreports api jar does not have all the Jasper Server/Jasper Studio built in functions such as DAYS / DAYSINMONTH etc. 

Exception in thread "main" net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: DAYS(DATE(1987,02,01),new Date())
    at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:291)
    at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:618)
    at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:586)
    at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:1020)
    at net.sf.jasperreports.engine.fill.JRFillTextField.evaluateText(JRFillTextField.java:568)
    at net.sf.jasperreports.engine.fill.JRFillTextField.evaluate(JRFillTextField.java:552)
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:281)
    at net.sf.jasperreports.engine.fill.JRFillFrame.evaluate(JRFillFrame.java:163)
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:281)
    at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:504)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2026)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillGroupHeader(JRVerticalFiller.java:613)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillGroupHeaders(JRVerticalFiller.java:535)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:161)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:558)
    at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:396)
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:91)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:456)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:863)
    at jasperSpfinalTest.FinalTestIterator.main(FinalTestIterator.java:84)
Caused by: java.lang.NoClassDefFoundError: net.sf.jasperreports.functions.standard.DateTimeFunctions

 

reportdev's picture
1226
Joined: Oct 12 2015 - 12:05pm
Last seen: 2 months 3 weeks ago
0

I think it's related to these libs. I'll try to check if they are already in the build path or not and i come back to give an answer.

siick's picture
24
Joined: Jul 3 2017 - 8:35am
Last seen: 1 year 7 months ago
0

OK, i can't check directly on production server... But i've tried a test. I have made a small simple report with some of DateTime functions which are inside jasperreports-functions libs... And it's pretty weird... NOW(), DAY(), SECOND(), DATEVALUE() are OK and functionnal, but DAYS(), YEARS(), MONTHS() give me the error mentionned here...

And these methods are using another method from joda-time lib, so it seems joda-time is the missing libray on theserver

siick's picture
24
Joined: Jul 3 2017 - 8:35am
Last seen: 1 year 7 months ago
0

I have checked my 6.4 Servers and the joda time jar is already there. The server should be shipped with the joda time jar.

If someone tried to delete the libraries, then this would occur from my understanding.

Just check your servers for any other missing libraries. 

reportdev's picture
1226
Joined: Oct 12 2015 - 12:05pm
Last seen: 2 months 3 weeks ago
Feedback