Web tier: servlets, JSP, Web frameworks: property file access at run time
I have a legacy application that reads property files on initialization. I can bundle them into a .jar file (properties.jar) and put the jar in my .war file, but I'm not sure how to get at the properties.jar in the .war file at runtime. Our previous deployment tools did something equivalent to expanding macros in the web.xml file (but not in a web.xml file). For example, if 'deployDir=$DEPLOY_DIR' were in the web.xml file, it would be expanded to a real path, and the java code could then access the $deployDir property.
- Posted by: Joe Felchlin
- Posted on: November 08 2001 14:50 EST
Is there something equivalent to this in the J2EE Web Container methodology, or is there an alternative approach?
You might be able to use getResource() or getResourceAsStream() in the ServletContext. From within a servlet, try:
java.io.InputStream is = getServletContext().getResourceAsStream("...");
What you pass into getResourceAsStream depends on where your properties.jar file is in the war file. If it's in the root of the war file, then just pass "properties.jar" to the method. You might have to play around with what you pass in to get it to work right.
Hope that helps,