The way I do it is to do something like the following:

URL url = getClass().getResource("/com/company/product/ThisClass.class");
String path = url.getPath();

The result ofpath will be something like
c:/java/mywork/classes/com/company/product/ThisClass.class

As I typically store config files in a directory called 'conf' at the same
level as com, I then use string methods to strip away the com portion
onwards, then look for the directory 'conf' containing my file.
If the class is in a jar file, the path will contain a '!' somewhere, and
the returned path will be the jar file name, so just strip this off.

sam

----- Original Message -----
From: "Chris Izquierdo" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 05, 2001 12:41 AM
Subject: War files and Config files


> Hi,
>
> I'm trying to deploy servlets using a WAR files. Everything works fine
except I can't read the configuration files from the servlet code.
>
> The code reading the configuration file is as follows:
>
> input = ClassLoader.getSystemResourceAsStream("test.properties");
> properties.load(input);
>
> This code assumes that the file "test.properties" is in the class path.
>
> Where should I put the property file in the WAR file so that it is in the
class path?
>
> If this can't be done, how should I structure my code around this problem?
>
> I'm using Tomcat 3.2
>
> Thank you very much
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to