title: net.sf.jasperreports.engine.JRRuntimeException: Function MONTH not found
body: <p>I'm working in a desktop application for generating reports with Java Swing and Jasper Reports. Some days ago I ran into a problem because of a Groovy function that my code was not able to find. I found <a href="https://stackoverflow.com/a/19459016/5310721">this answer</a> and the problem was solved (note I left a comment) but when I packaged my application and tried to run it from the console I got the same issue. This is the stacktrace:</p>
  
  <pre><code>net.sf.jasperreports.engine.JRRuntimeException: Function MONTH not found.
      at net.sf.jasperreports.compilers.GroovyEvaluator.functionCall(GroovyEvaluator.java:106)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:174)
      at subReporteSummary_1502405767221_591326.methodMissing(calculator_subReporteSummary_1502405767221_591326:22)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
      at groovy.lang.MetaClassImpl.invokeMissingMethod(MetaClassImpl.java:939)
      at groovy.lang.MetaClassImpl.invokePropertyOrMissing(MetaClassImpl.java:1262)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1215)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
      at subReporteSummary_1502405767221_591326.evaluateEstimated(calculator_subReporteSummary_1502405767221_591326:336)
      at net.sf.jasperreports.engine.fill.JREvaluator.evaluateEstimated(JREvaluator.java:342)
      ... 14 more
  </code></pre>
  
  <p>But when I inspect the jar I'm able to find the <code>MONTH</code> function, which is in the <code>net.sf.jasperreports.functions.standard.DateTimeFunctions</code> class</p>
  
  <pre><code>@Function("MONTH")
  @FunctionParameters({
      @FunctionParameter("dateObject")})
  public static Integer MONTH(Object dateObject){
      return getCalendarFieldFromDate(dateObject,Calendar.MONTH)+1;
  }
  </code></pre>
  
  <p>from the <code>jasperreports-functions</code> package which is in my classpath and is added to the package, as you may note by my maven configuration</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  
      &lt;repositories&gt;
          &lt;!-- Jasper Reports repository to get japerreports-functions --&gt;
          &lt;repository&gt;
              &lt;id&gt;jr-ce-releases&lt;/id&gt;
              &lt;url&gt;http://jaspersoft.artifactoryonline.com/jaspersoft/jr-ce-releases&lt;/url&gt;
          &lt;/repository&gt;
      &lt;/repositories&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;net.sf.jasperreports&lt;/groupId&gt;
              &lt;artifactId&gt;jasperreports&lt;/artifactId&gt;
              &lt;version&gt;6.4.0&lt;/version&gt;
              &lt;!-- Exclusions to avoid some JasperReports certificates problems --&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.bouncycastle&lt;/groupId&gt;
                      &lt;artifactId&gt;bcmail-jdk14&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;bouncycastle&lt;/groupId&gt;
                      &lt;artifactId&gt;bcmail-jdk14&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.bouncycastle&lt;/groupId&gt;
                      &lt;artifactId&gt;bctsp-jdk14&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;bouncycastle&lt;/groupId&gt;
                      &lt;artifactId&gt;bcprov-jdk14&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Groovy functions for Jasper Reports--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;net.sf.jasperreports&lt;/groupId&gt;
              &lt;artifactId&gt;jasperreports-functions&lt;/artifactId&gt;
              &lt;version&gt;5.2.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.codehaus.groovy&lt;/groupId&gt;
              &lt;artifactId&gt;groovy-all&lt;/artifactId&gt;
              &lt;version&gt;2.4.12&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Driver needed to connect to the DB --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.ibm.informix&lt;/groupId&gt;
              &lt;artifactId&gt;jdbc&lt;/artifactId&gt;
              &lt;version&gt;4.10.8.1&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;!-- This is to include all my dependencies in my package (it works fine) --&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.0.0&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;phase&gt;package&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;shade&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.0.2&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;archive&gt;
                          &lt;manifest&gt;
                              &lt;mainClass&gt;ar.edu.unt.gui.MainFrame&lt;/mainClass&gt;
                          &lt;/manifest&gt;
                      &lt;/archive&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
  
          &lt;resources&gt;
              &lt;resource&gt;
                  &lt;!-- I don't want to package the reports' source file --&gt;
                  &lt;directory&gt;src/main/resources&lt;/directory&gt;
                  &lt;excludes&gt;
                      &lt;exclude&gt;*.jrxml&lt;/exclude&gt;
                  &lt;/excludes&gt;
              &lt;/resource&gt;
          &lt;/resources&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>The <code>MONTH</code> function is called from a subreport. I found <a href="https://community.jaspersoft.com/questions/823601/netsfjasperreportsenginejrruntimeexception-increment-class-not-found-error" rel="nofollow noreferrer">this post</a> in the Jaspersoft Community but my report doesn't have such <code>&lt;returnValue&gt;</code> tag. This is the fragment from the main report where the subreport is declared:</p>
  
  <pre><code>&lt;summary&gt;
      &lt;band height="239" splitType="Stretch"&gt;
          &lt;subreport&gt;
              &lt;reportElement x="0" y="0" width="469" height="200" uuid="2da4b923-ee34-4a6d-9a04-8d050a2feb0f"/&gt;
              &lt;subreportParameter name="NRO_PAGINAS_PADRE"&gt;
                  &lt;subreportParameterExpression&gt;&lt;![CDATA[$V{PAGE_NUMBER}]]&gt;&lt;/subreportParameterExpression&gt;
              &lt;/subreportParameter&gt;
              &lt;connectionExpression&gt;&lt;![CDATA[$P{REPORT_CONNECTION}]]&gt;&lt;/connectionExpression&gt;
              &lt;subreportExpression&gt;&lt;![CDATA["subReporteSummary.jasper"]]&gt;&lt;/subreportExpression&gt;
          &lt;/subreport&gt;
          &lt;textField evaluationTime="Auto"&gt;
              &lt;reportElement x="175" y="219" width="126" height="20" uuid="28a4ff7e-d6dd-47f5-a655-5e0ea7bec50b"/&gt;
              &lt;textElement textAlignment="Center" verticalAlignment="Middle"/&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA["- Página " + $V{NRO_PAGINA_ACTUAL} + " de " + $V{PAGE_NUMBER} + " -"]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
      &lt;/band&gt;
  &lt;/summary&gt;
  </code></pre>
  
  <p>And this is the <code>subReporteSummary.jrxml</code> (summarySubreport in spanish) fragment where the MONTH function is called:</p>
  
  <pre><code>&lt;variable name="NOMBRE_MES" class="java.lang.String" resetType="None"&gt;
      &lt;variableExpression&gt;&lt;![CDATA[MONTH($F{fechacancelacion}) == 1? "Enero" :
      MONTH($F{fechacancelacion}) == 2? "Febrero" :
      MONTH($F{fechacancelacion}) == 3? "Marzo" :
      MONTH($F{fechacancelacion}) == 4? "Abril" :
      MONTH($F{fechacancelacion}) == 5? "Mayo" :
      MONTH($F{fechacancelacion}) == 6? "Junio" :
      MONTH($F{fechacancelacion}) == 7? "Julio" :
      MONTH($F{fechacancelacion}) == 8? "Agosto" :
      MONTH($F{fechacancelacion}) == 9? "Septiembre" :
      MONTH($F{fechacancelacion}) == 10? "Octubre" :
      MONTH($F{fechacancelacion}) == 11? "Noviembre" : "Diciembre"]]&gt;&lt;/variableExpression&gt;
      &lt;initialValueExpression&gt;&lt;![CDATA[MONTH($F{fechacancelacion}) == 1? "Enero" :
      MONTH($F{fechacancelacion}) == 2? "Febrero" :
      MONTH($F{fechacancelacion}) == 3? "Marzo" :
      MONTH($F{fechacancelacion}) == 4? "Abril" :
      MONTH($F{fechacancelacion}) == 5? "Mayo" :
      MONTH($F{fechacancelacion}) == 6? "Junio" :
      MONTH($F{fechacancelacion}) == 7? "Julio" :
      MONTH($F{fechacancelacion}) == 8? "Agosto" :
      MONTH($F{fechacancelacion}) == 9? "Septiembre" :
      MONTH($F{fechacancelacion}) == 10? "Octubre" :
      MONTH($F{fechacancelacion}) == 11? "Noviembre" : "Diciembre"]]&gt;&lt;/initialValueExpression&gt;
  &lt;/variable&gt;
  </code></pre>
  
  <p>briefly: <code>fechacancelacion</code> is a <code>java.util.Date</code> variable and the expression is for get the month's names in upper case (is a requirement), which I can't get with a <code>DATEFORMAT</code> function because it gives me the names only in lowercase.</p>
  
  <p>But getting back to the issue and to summarize, I have the <code>MONTH</code> function available in my JAR, the report compiles and shows correctly when I run my application from the IDE (Netbeans) but I'm getting an error running from the console with <code>java -jar myapp-1.0.jar</code> from the <code>target</code> folder.</p>
  
  <p>If you need any other evidence, comment it out. Any help will be appreciated. Thanks in advance for your answers</p>