On Fri, Feb 24, 2017 at 6:00 PM, Christopher Schultz < ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA256 > > Martin, > > On 2/21/17 8:31 AM, Martin Knoblauch wrote: > > Hi, > > > > is there a way to find the absolute path of the application root > > before the servlet is initialized? > > > > Alternatively: is there a way to defer the initialization of a > > datasource until the servlet is initialized? > > > > Background: I have extended > > "org.apache.tomcat.jdbc.pool.DataSourceFactory" to automatically > > set credentials so that they are not stored in the > > "Catalina/localhost/XXX.xml" file. Instead they are taken from > > encrypted values in a file below the application root. Works fine > > if I know that path at "createDataSource" time. > > Where are you configuring your <Resource>? In conf/server.xml or in > your application's META-INF/context.xml file? > conf/Catalina/localhost/XXX.xml > > > In order to avoid hard coding that path, I need a programmatic to > > find that value. Unfortunately the datasource is initialized before > > the servlet, so "getRealPath()" is not working yet. > > getRealPath is a bad idea. Also, your DataSources will be > fully-configured before any servlets are initialized, so it's too late. > > Correct :-( That is the problem I need(ed) to solve. Given enough assumptions about the deployment rules for this app, I was able to find a reliable way to deduce the AppRoot. But the fact that the DS is initialized before the/any servlet is still ugly. Thanks Martin