locating .properties files

2001-05-02 Thread Matthew O'Haire


Where should I put .properties file(s) in my WAR ?

Should they be in the application .jar (where I put the classes that use the
properties files, ie. the helpers used to implement the struts Actions), or
in the META-INF somewhere?

When I run the application under Forte it works fine with the .properties in
the META-INF/Classes directory, but once I've packed it up as a WAR it
doesn't run.  I getting a application generated runtime exception stating
that the properties file was not found...

I'm using the following code to locate and load the .properties:

  Properties p = new Properties();
  InputStream is =
Thread.currentThread().getContextClassLoader().getResourceAsStream("datasour
ce.properties");
  if (is == null) {
throw new RuntimeException("ConnectionFactory: could not find
'datasource.properties' configuration file");
  }
  p.load(is);

Any assistance would be greatly appreciated.

Thanks,
Matt.



Re: locating .properties files

2001-05-03 Thread Scott Walter

You should just have to put it somewhere in the
classpath (i.e. web-inf/classes)

scott.
--- Matthew O'Haire <[EMAIL PROTECTED]> wrote:
> 
> Where should I put .properties file(s) in my WAR ?
> 
> Should they be in the application .jar (where I put
> the classes that use the
> properties files, ie. the helpers used to implement
> the struts Actions), or
> in the META-INF somewhere?
> 
> When I run the application under Forte it works fine
> with the .properties in
> the META-INF/Classes directory, but once I've packed
> it up as a WAR it
> doesn't run.  I getting a application generated
> runtime exception stating
> that the properties file was not found...
> 
> I'm using the following code to locate and load the
> .properties:
> 
>   Properties p = new Properties();
>   InputStream is =
>
Thread.currentThread().getContextClassLoader().getResourceAsStream("datasour
> ce.properties");
>   if (is == null) {
> throw new RuntimeException("ConnectionFactory:
> could not find
> 'datasource.properties' configuration file");
>   }
>   p.load(is);
> 
> Any assistance would be greatly appreciated.
> 
> Thanks,
> Matt.


=
~~~
Scott

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



RE: locating .properties files

2001-05-03 Thread Nigel Ainslie

Hi Scott,
I work with Matt.thanks for the response. We have located the properties
file in WEB-INF/classes both at that directory level and at the directory
that the classes reside in (WEB-INF/classes/sub-directory/actualcode.class)
but we still get the same error. Even tried adding $TOMCAT
HOME.WEB-INF/classes to the classpath to no avail.
Is there some subtlety that we are missing?
Regards Nige


-Original Message-
From: Scott Walter [mailto:[EMAIL PROTECTED]]
Sent: Friday, 4 May 2001 7:18
To: [EMAIL PROTECTED]
Subject: Re: locating .properties files


You should just have to put it somewhere in the
classpath (i.e. web-inf/classes)

scott.
--- Matthew O'Haire <[EMAIL PROTECTED]> wrote:
> 
> Where should I put .properties file(s) in my WAR ?
> 
> Should they be in the application .jar (where I put
> the classes that use the
> properties files, ie. the helpers used to implement
> the struts Actions), or
> in the META-INF somewhere?
> 
> When I run the application under Forte it works fine
> with the .properties in
> the META-INF/Classes directory, but once I've packed
> it up as a WAR it
> doesn't run.  I getting a application generated
> runtime exception stating
> that the properties file was not found...
> 
> I'm using the following code to locate and load the
> .properties:
> 
>   Properties p = new Properties();
>   InputStream is =
>
Thread.currentThread().getContextClassLoader().getResourceAsStream("datasour
> ce.properties");
>   if (is == null) {
> throw new RuntimeException("ConnectionFactory:
> could not find
> 'datasource.properties' configuration file");
>   }
>   p.load(is);
> 
> Any assistance would be greatly appreciated.
> 
> Thanks,
> Matt.


=
~~~
Scott

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



RE: locating .properties files

2001-05-03 Thread Jason Chaffee
Title: RE: locating .properties files





You shouldn't be adding WEB-INF/classes to your classpath.  This should be running as a web app.


You should have the following in your deployment desciptor and you should have ApplicaionResoruces.properties in the WEB-INF/classes directory:

    
    ActionServlet
    org.apache.struts.action.ActionServlet
    
    application
    ApplicationResources
    
    
    config
    /WEB-INF/struts-config.xml
    
    
    locale
    true
    
    
    null
    false
    
    1
    


-Original Message-
From: Nigel Ainslie [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 03, 2001 4:29 PM
To: '[EMAIL PROTECTED]'
Subject: RE: locating .properties files



Hi Scott,
I work with Matt.thanks for the response. We have located the properties
file in WEB-INF/classes both at that directory level and at the directory
that the classes reside in (WEB-INF/classes/sub-directory/actualcode.class)
but we still get the same error. Even tried adding $TOMCAT
HOME.WEB-INF/classes to the classpath to no avail.
Is there some subtlety that we are missing?
Regards Nige



-Original Message-
From: Scott Walter [mailto:[EMAIL PROTECTED]]
Sent: Friday, 4 May 2001 7:18
To: [EMAIL PROTECTED]
Subject: Re: locating .properties files



You should just have to put it somewhere in the
classpath (i.e. web-inf/classes)


scott.
--- Matthew O'Haire <[EMAIL PROTECTED]> wrote:
> 
> Where should I put .properties file(s) in my WAR ?
> 
> Should they be in the application .jar (where I put
> the classes that use the
> properties files, ie. the helpers used to implement
> the struts Actions), or
> in the META-INF somewhere?
> 
> When I run the application under Forte it works fine
> with the .properties in
> the META-INF/Classes directory, but once I've packed
> it up as a WAR it
> doesn't run.  I getting a application generated
> runtime exception stating
> that the properties file was not found...
> 
> I'm using the following code to locate and load the
> .properties:
> 
>   Properties p = new Properties();
>   InputStream is =
>
Thread.currentThread().getContextClassLoader().getResourceAsStream("datasour
> ce.properties");
>   if (is == null) {
> throw new RuntimeException("ConnectionFactory:
> could not find
> 'datasource.properties' configuration file");
>   }
>   p.load(is);
> 
> Any assistance would be greatly appreciated.
> 
> Thanks,
> Matt.



=
~~~
Scott


__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/





Re: locating .properties files

2001-05-03 Thread Jeff Trent
Title: RE: locating .properties files



I have the same problem ... I need to keep the 
properties file in two places or else something gets wacked.  Haven't had 
the patience to research it any further...
 

  - Original Message - 
  From: 
  Jason 
  Chaffee 
  To: '[EMAIL PROTECTED]' 
  
  Sent: Thursday, May 03, 2001 7:36 
PM
  Subject: RE: locating .properties 
  files
  
  You shouldn't be adding WEB-INF/classes to your 
  classpath.  This should be running as a web app. 
  You should have the following in your deployment desciptor and 
  you should have ApplicaionResoruces.properties in the WEB-INF/classes 
  directory:
           
  ActionServlet     
  org.apache.struts.action.ActionServlet 
      
       
  application     
  ApplicationResources      
      
       
  config     
  /WEB-INF/struts-config.xml 
      
        
      
  locale     
  true      
      
       
  null     
  false      
      
  1      
  -Original Message- From: Nigel 
  Ainslie [mailto:[EMAIL PROTECTED]] 
  Sent: Thursday, May 03, 2001 4:29 PM To: '[EMAIL PROTECTED]' Subject: 
  RE: locating .properties files 
  Hi Scott, I work with Matt.thanks 
  for the response. We have located the properties file 
  in WEB-INF/classes both at that directory level and at the directory 
  that the classes reside in 
  (WEB-INF/classes/sub-directory/actualcode.class) but 
  we still get the same error. Even tried adding $TOMCAT HOME.WEB-INF/classes to the classpath to no avail. Is there some subtlety that we are missing? Regards Nige 
  -Original Message- From: Scott 
  Walter [mailto:[EMAIL PROTECTED]] 
  Sent: Friday, 4 May 2001 7:18 To: 
  [EMAIL PROTECTED] Subject: Re: locating 
  .properties files 
  You should just have to put it somewhere in the 
  classpath (i.e. web-inf/classes) 
  scott. --- Matthew O'Haire 
  <[EMAIL PROTECTED]> wrote: > 
  > Where should I put .properties file(s) in my WAR 
  ? > > Should they be in 
  the application .jar (where I put > the classes 
  that use the > properties files, ie. the helpers 
  used to implement > the struts Actions), or 
  > in the META-INF somewhere? > 
  > When I run the application under Forte it works 
  fine > with the .properties in > the META-INF/Classes directory, but once I've packed 
  > it up as a WAR it > doesn't 
  run.  I getting a application generated > 
  runtime exception stating > that the properties 
  file was not found... > > I'm using the following code to locate and load the 
  > .properties: > 
  >   Properties p = new 
  Properties(); >   InputStream is = 
  > Thread.currentThread().getContextClassLoader().getResourceAsStream("datasour 
  > ce.properties"); >   if (is == null) { > throw new 
  RuntimeException("ConnectionFactory: > could not 
  find > 'datasource.properties' configuration 
  file"); >   } >   p.load(is); > 
  > Any assistance would be greatly 
  appreciated. > > 
  Thanks, > Matt. 
  = ~~~ Scott 
  __ 
  Do You Yahoo!? Yahoo! Auctions - buy 
  the things you want at great prices http://auctions.yahoo.com/ 



RE: locating .properties files

2001-05-03 Thread Matthew O'Haire

Hi all,
 
We've found a solution to this, so for the benefit of the list here it is...
 
It seems Class.getResourceAsStream() and
ServletContext.getResourceAsStream(), the Javadoc for the latter says as
much:

This method has a different purpose than java.lang.Class.getResource, which
looks up resources based on a class loader. This method does not use class
loaders.

So it seems my original code worked in the IDE because Forte was including
my project in the classpath for starting the "embedded" Tomcat.
 
This meant that to manage resources we needed access to the ServletContext.
 
Rather than put references to "web layer" concepts in the "business layer"
we created a PropertiesFactory (singleton) class that was instantiated by
the LoginAction (with the ServletContext) and used by the business layer
without any reference to ServletContext.
 
We could have had the Factory surface ResourceStreams, but we thought that
by abstracting the access mechanism we could store propeties wherever we
wanted, as long as we surfaced them as java.util.Properties.
 
Anyhow, it works fine now in both the IDE and in production.  If anyone else
has a similar problem I'd be happy to share the code.  Thanks for the
feedback.
 
Matt.
 

-Original Message-
From: Jeff Trent [mailto:[EMAIL PROTECTED]]
Sent: Friday, 4 May 2001 14:29
To: [EMAIL PROTECTED]
Subject: Re: locating .properties files


I have the same problem ... I need to keep the properties file in two places
or else something gets wacked.  Haven't had the patience to research it any
further...
 

- Original Message - 
From: Jason  <mailto:[EMAIL PROTECTED]> Chaffee 
To: '[EMAIL PROTECTED]'
  
Sent: Thursday, May 03, 2001 7:36 PM
Subject: RE: locating .properties files


You shouldn't be adding WEB-INF/classes to your classpath.  This should be
running as a web app. 

You should have the following in your deployment desciptor and you should
have ApplicaionResoruces.properties in the WEB-INF/classes directory:

 
ActionServlet 
 
org.apache.struts.action.ActionServlet 
 
application 
ApplicationResources 
 
 
config 
/WEB-INF/struts-config.xml 
 
 
locale 
true 
 
 
null 
false 
 
1 
 

-Original Message- 
From: Nigel Ainslie [ mailto:[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> ] 
Sent: Thursday, May 03, 2001 4:29 PM 
To: '[EMAIL PROTECTED]' 
Subject: RE: locating .properties files 


Hi Scott, 
I work with Matt.thanks for the response. We have located the properties

file in WEB-INF/classes both at that directory level and at the directory 
that the classes reside in (WEB-INF/classes/sub-directory/actualcode.class) 
but we still get the same error. Even tried adding $TOMCAT 
HOME.WEB-INF/classes to the classpath to no avail. 
Is there some subtlety that we are missing? 
Regards Nige 


-Original Message- 
From: Scott Walter [ mailto:[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> ] 
Sent: Friday, 4 May 2001 7:18 
To: [EMAIL PROTECTED] 
Subject: Re: locating .properties files 


You should just have to put it somewhere in the 
classpath (i.e. web-inf/classes) 

scott. 
--- Matthew O'Haire <[EMAIL PROTECTED]> wrote: 
> 
> Where should I put .properties file(s) in my WAR ? 
> 
> Should they be in the application .jar (where I put 
> the classes that use the 
> properties files, ie. the helpers used to implement 
> the struts Actions), or 
> in the META-INF somewhere? 
> 
> When I run the application under Forte it works fine 
> with the .properties in 
> the META-INF/Classes directory, but once I've packed 
> it up as a WAR it 
> doesn't run.  I getting a application generated 
> runtime exception stating 
> that the properties file was not found... 
> 
> I'm using the following code to locate and load the 
> .properties: 
> 
>   Properties p = new Properties(); 
>   InputStream is = 
> 
Thread.currentThread().getContextClassLoader().getResourceAsStream("datasour

> ce.properties"); 
>   if (is == null) { 
> throw new RuntimeException("ConnectionFactory: 
> could not find 
> 'datasource.properties' configuration file"); 
>   } 
>   p.load(is); 
> 
> Any assistance would be greatly appreciated. 
> 
> Thanks, 
> Matt. 


= 
~~~ 
Scott 

__ 
Do You Yahoo!? 
Yahoo! Auctions - buy the things you want at great prices 
http://auctions.yahoo.com/ <http://auctions.yahoo.com/>