title: Importing and using groovy code in GSP
body: <p>I am trying to use a groovy function inside a GSP.  Please help as I am about to tare my hair out here.</p>
  
  <p>At the top of my GSP i have <code>&lt;%@ page import = company.ConstantsFile %&gt;</code></p>
  
  <p>Inside my GSP I have </p>
  
  <pre><code>&lt;p&gt;
  I have been in the heating and cooling business for &lt;%(ConstantsFile.daysBetween())%&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>and my ConstantsFile.groovy</p>
  
  <pre><code>package company
  
  import static java.util.Calendar.*
  
  class ConstantsFile {
  
      def daysBetween() {
          def startDate = Calendar.instance
          def m = [:]
          m[YEAR] = 2004
          m[MONTH] = "JUNE"
          m[DATE] = 26
          startDate.set(m)
          def today = Calendar.instance
  
          render today - startDate
      }
  }
  </code></pre>
  
  <p>I have also tried changing renter to puts, system.out, etc but that isn't my main problem.</p>
  
  <pre><code>Error 500: Internal Server Error
  URI
  /company/
  Class
  java.lang.NullPointerException
  Message
  Cannot invoke method daysBetween() on null object
  </code></pre>
  
  <p>So I try </p>
  
  <pre><code>&lt;p&gt;
      I have been in the heating and cooling business for &lt;%(new ConstantsFile.daysBetween())%&gt;
      &lt;/p&gt;
  </code></pre>
  
  <p>but then i get </p>
  
  <pre><code>Class: org.codehaus.groovy.control.MultipleCompilationErrorsException
  
  unable to resolve class ConstantsFile.daysBetween @ line 37, column 1. (new ConstantsFile.daysBetween()) ^ 1 error
  </code></pre>
  
  <p>Please someone help me or point me to a website that shows what to do.. I have tried googling and everything talks about a g:select or some other kind of tag... I just want to output the result of the function like I used to in the JSPs.</p>