I have a central class (RuntimeConfiguration
) that holds around 100
parameters for my application. These parameters are taken from an XML file which I stored in the WEB-INF
folder. On my development box, I hard-coded the path, but for very obvious reasons, this is not a productive solution.
For portability reasons (my application might be executed on a Tomcat or a Jetty and under Windows OR Unix), I want to have a generic access way to this file from within my RuntimeConfiguration
class.
I know, I can use getRealPath
in case I have a servlet, BUT RuntimeConfiguration
is NOT started within a servlet context. It is invoked from a job (a crawler) which in turn is started from quartz job control via applicationContext.xml
. Now this seems to be the core of my problem.
Can anyone tell me, how to get the absolute path to my XML in this environment?
I tried this ClassLoader
approach, but it gives me a NullPointerException
:
ClassLoader loader = this.getClass().getClassLoader();
loader.getResource("WEB-INF");
result = loader.getSystemResource(RTCF).toString();
I also tried
URL url = this.getClass().getClassLoader().getResource("WEB-INF");
which also throws a null pointer exception
Can anyone give me a portable solution, one that works on my dev-machine and on a production system where my application is deployed as a WAR-file?
By the way, the method should at best be able to handle Windows AND Mac OS X / Unix based systems.
NPE
? You can add stacktrace for better understanding. – TroublemakerRuntimeConfiguration
is declared as bean in your web application context ? – Troublemaker