Thanks for the answer, I found a cool implementation of Resource.java which does a few nifty things and error reporting etc. It's small but works well.
Another question, my web app logs to the "default directory" because I don't know at run time where to put my log files. Problem is, when Tomcat runs as a service, the log files get put in \WINDOWS\System32 - not the nicest place for clutter :-) -----Original Message----- From: Shapira, Yoav [mailto:[EMAIL PROTECTED] Sent: 13 May 2004 15:08 PM To: Tomcat Users List Subject: RE: Default Directory Hi, >With Tomcat 5.0.24 running as a service, where would the "current >directory" >be? 5.0.18 allowed you to specify --WorkingPath "%CATALINA_HOME%\bin" in >service.bat, but this setting is ignored now in 5.0.24. > >I need to open some config files from the current directory at startup. > >BTW how does the technique work to "grab a resource" from the CLASSPATH? >Maybe I only need to put the config files in the classpath in that case. >(or in the WEB-INF directory of the service?). Using Class#getResource is a great portable way to read configuration files. Place the config files under WEB-INF/classes, and then say (from any object) getClass().getResource("/myFile.prop") to get a URL to the file (for libraries that will take a URL), or getResourceAsStream to get an InputStream for reading. Read the JavaDoc for Class#getResource (actually ClassLoader#getResource as you'll see) for full details. Using ServletContext#getResource is similar and also very good. Files don't have to be on the classpath, they can be anywhere under the webapp's root directory. For example, put them under WEB-INF/config and call getServletContext().getResource("/WEB-INF/config/myFile.prop") to get the URL, or getResourceAsStream for the stream. Either of those approaches is many times better than the current working directory approach, which is the portability equivalent of a fly on the path of a sumo wrestler to his food. Yoav Shapira This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] ************************************************************************************************************************** Everything in this e-mail and attachments relating to the official business of MultiChoice Africa is proprietary to the company. Any view or opinion expressed in this message may be the view of the individual and should not automatically be ascribed to the company. If you are not the intended recipient, you may not peruse, use, disseminate, distribute or copy this message. If you have received this message in error, please notify the sender immediately by email, facsimile or telephone and destroy the original message. ************************************************************************************************************************** --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
