I found that it looks in c:\windows\system32 by default.  Try throwing
it in there.
 
If you're using Tomcat, if you put a / before the filename, it will just
look in the root directory of whatever drive Tomcat sits in.

Jan

-----Original Message-----
From: Clark Dorman [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 12, 2005 1:12 PM
To: [email protected]
Subject: Re: How to find a Properties file


Yes, that did it.  Thanks.  

(Actually, it was marginally different since all the functions 
in Configuration were static, so this. doesn't work.  I just 
opened the inputstream in ConfigurationServlet and passed it in.)

Putting the file in WEB-INF/classes/data/config/stock.properties
did _not_ work, but I have no idea why.

Clark


> Jeff Greif wrote:
> 
> If you read the properties file using the stream produced by the
method 
> ClassLoader.getResourceAsStream
> the file will be found in the jar if the jar is in the classpath used
by 
> the ClassLoader.
> 
> Thus,
>   Configuration conf = ....
>   InputStream stream = conf.getClass().getClassLoader()
>       .getResourceAsStream("data/config/stock.properties");
> should give the stream you need (or this.getClass().... if used inside

> the constructor of Configuration).
> 
> Jeff
> 
> Clark Dorman wrote:
> 
> >My web service needs to read a properties file but cannot find it.
The
> >properties file is currently in the jar containing the web service,
so
> >the jar contains things like:
> >
> >     com.ncc.wrap.Configuration.class
> >     ....
> >     com.ncc.wrap.StockService.class
> >     ...
> >     data/config/stock.properties
> >
> >The Configuration class reads the properties and the StockService
class
> >uses them.  When I run it as a normal jar, Configuration can find the

> >properties file (the jar is in the classpath), but running under
Axis, I
> >get an exception that it cannot find the properties file.  How do I
tell
> >Configuration to find the file?  The error I get in Tomcat's log is:
> >
> >com.ncc.wrap.WRAPException: Unable to open file: 
> >data/config/stock.properties
> >     at com.ncc.wrap.Configuration.initialize(Configuration.java:160)
> >
> >
> >I have tried to use a servlet to help.  The ConfigurationSerlet.java 
> >class has a function:
> >
> >  public void init()
> >    {
> >        ServletContext sc = getServletConfig().getServletContext();
> >        try
> >        {
> >            Configuration.initialize(sc);
> >        }
> >        catch (Exception ex)
> >        {
> >            ex.printStackTrace();
> >        }
> >    }
> >
> >and I add to the Axis web.xml the following:
> >
> >
> >  <servlet>
> >      <servlet-name>WRAPConfiguration</servlet-name>
> >
<servlet-class>com.ncc.wrap.ConfigurationServlet</servlet-class>
> >      <load-on-startup>1</load-on-startup>
> >  </servlet>
> >
> >and change Configuration.java to include a function that takes a
servlet
> >context in the initialization:
> >
> >             String resource = "/" + DEFAULT_CONFIG_FILE;
> >            InputStream is = sc.getResourceAsStream( resource );
> >            
> >            logger.info(" input stream was: " + is + ".  Resource
was: "
> >+                                    resource);
> >            logger.info("servlet context" + sc );
> >
> >            wrapProperties.load(is);
> >
> >However, the problem with this is that the InputStream 'is' is null. 
> >I've tried lots of variations but no luck.
> >
> >Any help would be greatly appreciated.
> >
> >Clark
> >

Reply via email to