Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8407769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:27:29+00:00 2026-06-09T23:27:29+00:00

I have a Grails 2.1 application in development, and I have a service that

  • 0

I have a Grails 2.1 application in development, and I have a service that is calling Thread.currentThread().contextClassLoader.getResource(fileName) to load a configuration file in grails-app/conf (I’m hoping the location doesn’t matter, though).

It works just fine, except that I have to restart the grails application to load changes to the config file. I’d really like to be able to read the file contents every single time I ask for the resource, at least during development.

Also, I’d like to avoid writing my own caching system if I can avoid it. The simpler the solution, the better.

My problem seems to be similar to this one with velocity but using getClass().getClassLoader().getResource(path).openStream() does not seem to work.

EDIT: I think I may have left out an important detail. The resource that I am retrieving is non-static. I am using the grails template engine to inject values into the resource like so:

Map bindings = [keys: 'values']
new SimpleTemplateEngine().createTemplate(resource).make(bindings).toString()

Using my debugger, I have found that the resource text isn’t changing, but knowing the above may change potential answers.

EDIT #2: I tried using URLConnection.setUseCaches(false) like so with no luck:

URLConnection connection = Thread.currentThread().contextClassLoader.getResource(path).openConnection()
connection.setUseCaches(false)
connection.connect()
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))
String content = reader.readLines().join('\n')
reader.close()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:27:30+00:00Added an answer on June 9, 2026 at 11:27 pm

    If you’re using a resource in this manner, you might consider moving it out of grails-app/conf and into /web-app.

    When running grails run-app, a cached version of an exploded war is actually running in a container with some outside magic monitoring various paths for changes and re-compiling and re-copying updated files similar to how one might manually hot-swap .class files and other resources.

    This monitoring happens out of the box for all files in /web-app. Once the files are there, you can use the ServletContext to get a handle to the file in question. For example, you might do something like:

    def templateFile = new File(ServletContextHolder.servletContext.getRealPath('/templates/fileName.gsp')).text
    

    and pass that to your templating engine. For environments that lock down the file system (e.g. Heroku), the getRealPath method will likely not work. You can, alternatively, use something like:

    import org.apache.commons.io.IOUtils
    def template =  IOUtils.toString(ServletContextHolder.servletContext.getResourceAsStream('/templates/fileName.gsp'), "UTF-8")
    

    The downsides to this approach:

    • You’ll need access to the ServletContext which will require you to have a container loaded. Therefore, no unit testing on this piece of coding; you’ll want an integration test instead.
    • Putting resources like this in /web-app will make them public. Alternatively, you could place them in /web-app/WEB-INF if privacy is a concern.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created one service in my grails application. in that service 25 methods
I have one grails application.In that I have one model class named Book. From
I have a groovy/grails application that needs to serve images It works fine on
We have an application in Grails 2.0 that we have working when we run
I have a Grails application, built to a war file (~30mb). When I attempt
I am maintaining a Grails application that I did not write(I have no experience
I have a grails application that attempts to use OpenID4Java to authenticate with our
I have a Grails application that I am migrating from 1.0.3 to 1.3.7 It
I have an existing grails application that uses spring-security plugin for authentication. I would
In my grails application I have an sql query that selects column data from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.