If you MUST create a File object, then you really need to know the full
path of the file somehow.  You can try using
servletContext.getRealPath("/WEB-INF/classes/" + configFileName) but
that will mean that you cannot distribute your webapp as a packed WAR,
and it may not work in other circumstances (depending on the appserver,
security settings, etc.)

And of course, you can put the file wherever you want in the webapp, it
doesn't have to be in classes (and probably shouldn't be, since it's not
a class, natch).  Just pass getRealPath the path relative to the context
root.

-- 
Tim Moore / Blackboard Inc. / Software Engineer
1899 L Street, NW / 5th Floor / Washington, DC 20036
Phone 202-463-4860 ext. 258 / Fax 202-463-4863


> -----Original Message-----
> From: aps olute [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, December 19, 2002 2:14 PM
> To: Tomcat Users List
> Subject: RE: How to start a standalone app from a servlet and 
> problems with reading properties file
> 
> 
> 
>    The problem is someone else had written the support class. 
> The support class will only take (File f) as its argument in 
> its constructor. The support classes are written by separate 
> developers. I can make changes to the portion I am 
> responsible for but cant do much with the other part.  
> Anyhow, the support class is having a fit not finding this 
> file to read. My servlet sits at mycontext/WEB-INF/classes/  
> and the support class sits at mycontext/WEB-INF/classes/util/ 
>  so the relative path to that support class is then 
> mycontext/WEB-INF/classes/util/ and this is where I would put 
> the file it needs?
> 
> --- Tim Moore <[EMAIL PROTECTED]> wrote:
> > Well when you call getResourceAsStream, the path is 
> resolved relative 
> > to the package the class is in, so if the servlet and the support 
> > class are in different packages, this would be expected.
> > 
> > What if you call it on the servlet class from the support class?
> > 
> > e.g.,
> > 
> > InputStream is = 
> WhateverTheServletIsCalled.class.getResourceAsStream(
> > parmPassedFromServlet )
> > 
> > or even better, instead of passing the file name from the 
> servlet to 
> > the support class, why not have the servlet just load the 
> properties 
> > and pass the properties object to the support class?
> > 
> > --
> > Tim Moore / Blackboard Inc. / Software Engineer
> > 1899 L Street, NW / 5th Floor / Washington, DC 20036
> > Phone 202-463-4860 ext. 258 / Fax 202-463-4863
> > 
> > 
> > > -----Original Message-----
> > > From: aps olute [mailto:[EMAIL PROTECTED]]
> > > Sent: Thursday, December 19, 2002 1:45 PM
> > > To: Tomcat Users List
> > > Subject: Re: How to start a standalone app from a servlet and 
> > > problems with reading properties file
> > > 
> > > 
> > > 
> > >  Tim,
> > >     Thanks for responding. Partial success was I was able to
> > > read the properties file using code snippet below in the 
> > > servlet init() method:
> > > 
> > >   Properties p = new Properties();
> > >   InputStream is = getClass().getResourceAsStream(configFileName);
> > > //configFileName is test.properties
> > >   p.load(is)
> > > 
> > > This property file is loaded and parsed for a property needed
> > > by a support class. The parameter read is passed to the 
> > > support class. When doing exact same InputStream is = 
> > > getClass().getResourceAsStream(parmPassedFromservlet); in the 
> > > support class, Tomcat does not start. I posted this earlier 
> > > last week on: 
> > > http://marc.theaimsgroup.com/?l=tomcat-user&m=103982860916736&;
> > w=2
> > 
> > Basically, I am facing two issues, 1) dependent on where I start 
> > Tomcat from and  2) Using getResourceAsStream() fails in 
> the support 
> > class. Any tips would be appreciated. Thanks.
> > 
> > __________________________________________________
> > Do you Yahoo!?
> > Yahoo! Mail Plus - Powerful. Affordable. Sign up now. 
> > http://mailplus.yahoo.com
> > 
> > --
> > To unsubscribe, e-mail: 
> > <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail: 
> > <mailto:[EMAIL PROTECTED]>
> > 
> > 
> > --
> > To unsubscribe, e-mail:   
> <mailto:tomcat-user-> [EMAIL PROTECTED]>
> > For 
> additional commands, 
> e-mail: 
> > <mailto:[EMAIL PROTECTED]>
> > 
> 
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now. 
http://mailplus.yahoo.com

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


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

Reply via email to