2

My web application uses the same database configuration as the application XYZ. I have a resource declaration for a context in server.xml, so I have a duplicated configuration (once for web application and once for application XYZ). How can I read some 'external' values into server.xml? For example:

<Resource name="jdbc/MyDB" username="${user}" password="${pwd}" url="${url}" ...
Ivan Bosnic
  • 1,916
  • 5
  • 21
  • 31
  • I don't quite understand how this is a duplication? I would understand it if user/pass/url were the same for both applications (i.e. the entire `` tag), but this is not true in your case. They're actually different! Can you please elaborate a bit more about the "duplication" you're talking about? – BalusC Nov 16 '09 at 18:22
  • But I sad: "same database configuration", so user/pass/url are the same. – Ivan Bosnic Nov 16 '09 at 18:28
  • Then just define a global datasource? – BalusC Nov 16 '09 at 18:37
  • Another application is not a web application. That is why I want to share database config in a unique and separate file. – Ivan Bosnic Nov 16 '09 at 19:07
  • Are you using Ant by any chance to build your web application? If so I might be able to help you out. – StevenWilkins Nov 16 '09 at 21:10

1 Answers1

1

In short - you can't do this with tomcat configuration. Also, specific for server.xml, the only way to reload it is to restart the server.

If you need the datasource only within one web application, then a way to do it is by using the spring framework and PropertyPlaceholderConfigurer.

Another way might be to inherit from tomcat's StandardHost and StandardContext and do some custom parsing.

David Rabinowitz
  • 29,904
  • 14
  • 93
  • 125