IntelliJ Java IDE
The moose likes Tomcat and the fly likes custom configuration file in Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Reply Bookmark "custom configuration file in Tomcat" Watch "custom configuration file in Tomcat" New topic
Author

custom configuration file in Tomcat

bujin wang
Ranch Hand

Joined: Jun 21, 2003
Posts: 48
Hi,
I have a application deployed into Tomcat. It's basically a jar file. This application has some settins sticked into the jar file. Then I could use this.getClass().getResourceAsStream("filename.properties") to load the settings in. However, after deploy, we might need to change these settings. That requires to open the jar and change the configuration file. I would like to put my configuration file outside the jar and have application to find it automatically. The problem is the application don't know where we are going to put the file before hand. Do you guys have ideas about that? The configuration contains a dozen of settings which perhaps it's not a good idea to leave them in system properties.
Thanks,
Bujin
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

the most common approach for this problem in web-app development is to use the WEB-INF/classes directory.

Items placed there can be loaded by the getResourceAsStream
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Specifically for Tomcat users, this has an additional advantage:

Tomcat will look in the WEB-INF/classes directory before attempting the WEB-INF/lib directory.

So with clever coding, you can get a situation where the default properties are included with the jar file, but to override those settings, simply put that same properties file in the WEB-INF/classes directory, with appropriately overriden values... and it should be found first.
bujin wang
Ranch Hand

Joined: Jun 21, 2003
Posts: 48
Thanks guys. That is helpful.
Bujin
 
 
subject: custom configuration file in Tomcat
 
Threads others viewed
ClassNotFoundException is very odd
Volatile property files
Tomcat webapp
error in downloading file
JDBC Driver not found.
IntelliJ Java IDE