At 02:46 PM 8/27/2002 +0800, randie ursal wrote:

>  here is the scenario, i have a servlet that will read a ".properties" 
> file and i make use
>  of PropertyResourceBundle to read the value from it.
>
>  the problem is that the PropertyResourceBundle doesn't find the 
> properties file.
>  the API for ResourceBundle said that my properties file must be set on 
> the classpath.
>  so, how do i set the classpath variable on Tomcat so that my properties 
> file will
>  be located...i tried placing my properties file on the /lib directory of 
> my web application
>  but it doesn't work...or do i have to explicitly include it on my 
> classpath environment
>  variable?

You can see the contents of the classpath variable by printing out
System.getProperty ("java.class.path").  You'll notice that whatever
you set it to outside Tomcat, inside it will be set to something
completely different (in my case, two jars of Tomcat classes).  This
is probably (I'm newbie-ish, too) a good thing; Tomcat is preventing
servlets from being affected by any environment variables you happen
to have set when you ran it.

In general, the strong impression I have is that you should never do
anything involving the classpath when writing a servlet.  Any classes
you need should be placed in WEB-INF (classes or lib).

I found a way to load in properties files, but it might not be Correct.
Properties files can be put in the same folder that contains WEB-INF,
and then accessed this way:

public class MyServlet extends HttpServlet
   Properties myProps;
   public void loadProps()
   {
     String propsPath = getServletContext().getRealPath("myprops.txt");
     myProps.load (new FileInputStream (propsPath));
   }
   ...
}

You'd want to clean up the above, naturally, using the file.separator
property instead of "/", and likely putting your props file in a
subfolder.  The above is just for quick-and-dirty brevity.

With that said, I do have some reservations with the above.  Something
doesn't feel right about it.


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to