| From | Sent On | Attachments |
|---|---|---|
| echa...@TXU.COM | Dec 4, 2002 1:35 pm | |
| Will Hartung | Dec 4, 2002 2:41 pm | |
| Roberto Bouza | Dec 4, 2002 2:48 pm | |
| Jay Wright | Dec 4, 2002 3:13 pm | |
| micael | Dec 4, 2002 3:25 pm | |
| Jay Wright | Dec 4, 2002 3:37 pm | |
| Will Hartung | Dec 4, 2002 3:46 pm | |
| Jacob Kjome | Dec 4, 2002 4:56 pm | |
| micael | Dec 4, 2002 5:12 pm | |
| Craig R. McClanahan | Dec 4, 2002 7:23 pm |
| Subject: | Re: Loading Properties Files | |
|---|---|---|
| From: | Will Hartung (wil...@msoft.com) | |
| Date: | Dec 4, 2002 3:46:05 pm | |
| List: | org.apache.tomcat.users | |
If you're using the ClassLoader to locate your properties files, then the properties files need to be within your classpath. For WARs, the only places that you really have much control over is the 'classes' directory.
The other issue is that your can not assume that you will be able to write to you properties files.
Will
----- Original Message ----- From: "Jay Wright" <jwri...@once.com> To: "'Tomcat Users List'" <tomc...@jakarta.apache.org> Sent: Wednesday, December 04, 2002 3:37 PM Subject: RE: Loading Properties Files
If I understand you correctly, the properties file CANNOT be in the war file, it needs to be external. Right.
-----Original Message----- From: micael [mailto:cara...@harbornet.com] Sent: Wednesday, December 04, 2002 3:25 PM To: Tomcat Users List Subject: RE: Loading Properties Files
Depends upon what you want to do with the properties files and how you access them. Some ways of accessing them require that the name to access be relative to the classpath, others don't. You are better off to learn about properties files in this instance. There is nothing peculiar to the web-structure that I know of that is important about locating properties files.
At 03:14 PM 12/4/2002 -0800, you wrote:
And if you have a .war file? Then where would you put your properties files?
-----Original Message----- From: Roberto Bouza [mailto:rbo...@efcholdings.com] Sent: Wednesday, December 04, 2002 2:49 PM To: Tomcat Users List Subject: Re: Loading Properties Files
Thats right.
If you don't have a .war file, you can use the classes dir inside your WEB-INF dir, and create a new directory like "conf", the put inside all the properties files. In that way the ClassLoader looks for the files in there when you use something like this:
try { Properties props = new Properties(); InputStream in = getClass().getResourceAsStream("/conf/db.properties"); props.load(in); ......
propertie1 = props.getProperty("propertie1");
C'ya
Quoting Will Hartung <wil...@msoft.com>:
From: <echa...@TXU.COM> Subject: Loading Properties Files
My problem is that the class cannot location my properties file. I am unable to use other suggested methods that I have noticed on this list since those problems involved Properties File within Servlets.
After some testing, I determined for some reason the default directory it is looking for my properties file is the Windows System Directory
(Determined this
by
opening a file in the default directory, outputing something in it and searching for the file).
Anyone have any ideas on how to solve this problem? I do not want to hard code the exact location due to obvious reasons
The problem is that you appear to be loading a file with an absolute path, versus the common form of load a properties file via the ClassLoader.
Fumble about with the ClassLoader.getResourceAsStream to have it hunt down your properties file, and then feed that stream to your Properties.
public static yourMethod() { ClassLoader cl = YourClass.class.getClassLoader(); Properties prop = new Properties(); prop.load(cl.getResourceAsStream("yours.properties")); }
Then, just drop your properties at the right place in your WARs classes area.
Regards,
Will Hartung (wil...@msoft.com)
-- = Roberto Bouza Fraga = =================================== Research & Development Engineer Ella Cisneros Fontanals Holdings Ph: (305)-860-0116 / Fax:(305)-860-9401 =================================== e-Mail:rbo...@efcholdings.com
-- To unsubscribe, e-mail:
<mailto:tomc...@jakarta.apache.org> For additional commands, e-mail: <mailto:tomc...@jakarta.apache.org>
-- To unsubscribe, e-mail:
<mailto:tomc...@jakarta.apache.org>
For additional commands, e-mail:
<mailto:tomc...@jakarta.apache.org>
Micael
-------------------------------------------------------
This electronic mail transmission and any accompanying documents contain information belonging to the sender which may be confidential and legally privileged. This information is intended only for the use of the individual or entity to whom this electronic mail transmission was sent as indicated above. If you are not the intended recipient, any disclosure, copying, distribution, or action taken in reliance on the contents of the information contained in this transmission is strictly prohibited. If you have received this transmission in error, please delete the message. Thank you





