Search code examples
javatomcat6classloader

Loading an config file form application classpath


I am loading a config file form application class path using getClass().getResourceAsStream().

The file is loaded when the application is started using apache tomcat server.

When i make some changes to the config file while the server is runnning, It is not picking up the changes.

I may need to make some changes when the application is running. Is there a way apache tomcat loads the config file after it is changed?


Solution

  • I assume you are re-reading the file, but you are definitely seeing the same contents even though you changed it?

    For now, I would print out the contents each time you poll the file, so you can see that a) the file is being polled, and b) the contents is/is not changing.

    Another possibility is that when you build an application a config file can end up in a number of places, e.g. in more than one JAR or also on your file system. Depending on your classpath, it could be that the file you are changing is not the one you are reading. i.e. is the directory first in the class path.

    EDIT: Can you log the URL, getClass().getResource(fileName) as this will show where the file is being loaded from?