• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

custom configuration file in Tomcat

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys. That is helpful.
Bujin
 
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic