You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Richard Gregory <ri...@gsf.de> on 2006/02/09 15:21:07 UTC

where to put file so web service can read it?

Hi,

I have a web service which needs to read a property from a configuration 
file, but I can't work out where in the webapp to put the configuration 
file so the web service implmentation class can read it. I've tried 
putting it in WEB-INF/classes, in the root directory of the web app, in 
WEB-INF, in the same directory as the class which reads it, and in 
pretty much every other directory you can think of, but I keep getting a 
FileNotFoundException.

If I hard code the full path to the file (C:/..... on Windows or 
/home/richard...... on Linux) in my service it can find and read it, but 
this isn't really an option as the service will be deployed on different 
machines by different customers so the path will vary.

If anyone can give me some suggestions I'd be grateful.

Thanks,

Richard.

Re: where to put file so web service can read it? :VSMail mx1

Posted by Dave Overbeck <do...@turnkey.com>.
Here's one approach (I believe this is called the "brute force" method). 
Where you're trying to read a file, write one instead. Don't specify a path, 
and give it a funny name. Then search your system and see where it turned 
up. The config file goes right next. It may not seem like the most 
convenient or intuitive location, probably somewhere deep in the bowels of 
your application server, but it should at least be consistent.

BTW you may find some interesting logs there. It's a bit like playing 
ADVENT.

Hope this helps,
Dave




> Hi,
>
> I have a web service which needs to read a property from a configuration 
> file, but I can't work out where in the webapp to put the configuration 
> file so the web service implmentation class can read it. I've tried 
> putting it in WEB-INF/classes, in the root directory of the web app, in 
> WEB-INF, in the same directory as the class which reads it, and in pretty 
> much every other directory you can think of, but I keep getting a 
> FileNotFoundException.
>
> If I hard code the full path to the file (C:/..... on Windows or 
> /home/richard...... on Linux) in my service it can find and read it, but 
> this isn't really an option as the service will be deployed on different 
> machines by different customers so the path will vary.
>
> If anyone can give me some suggestions I'd be grateful.
>
> Thanks,
>
> Richard. 


Re: where to put file so web service can read it?

Posted by Richard Gregory <ri...@gsf.de>.
Thanks to everyone who replied. I now have a choice of methods for 
solving the problem. :-)

Richard.

Junaid.Bhatra@mro.com wrote:

>Put your config file under /WEB-INF. You can then read this as follows:
>
>InputStream is = servletContext.getResourceAsStream("/WEB-INF/" +
>configFile);
>
>Read this wiki on how to obtain the ServletContext from within your Web
>Service:
>http://wiki.apache.org/ws/FrontPage/Axis/ServletContext
>
>-Junaid
>
>
>
>
>                                                                           
>             Richard Gregory                                               
>             <richard.gregory@                                             
>             gsf.de>                                                    To 
>                                       axis-user@ws.apache.org             
>             02/09/2006 09:21                                           cc 
>             AM                                                            
>                                                                   Subject 
>                                       where to put file so web service    
>             Please respond to         can read it?                        
>             axis-user@ws.apac                                             
>                  he.org                                                   
>                                                                           
>                                                                           
>                                                                           
>                                                                           
>
>
>
>
>Hi,
>
>I have a web service which needs to read a property from a configuration
>file, but I can't work out where in the webapp to put the configuration
>file so the web service implmentation class can read it. I've tried
>putting it in WEB-INF/classes, in the root directory of the web app, in
>WEB-INF, in the same directory as the class which reads it, and in
>pretty much every other directory you can think of, but I keep getting a
>FileNotFoundException.
>
>If I hard code the full path to the file (C:/..... on Windows or
>/home/richard...... on Linux) in my service it can find and read it, but
>this isn't really an option as the service will be deployed on different
>machines by different customers so the path will vary.
>
>If anyone can give me some suggestions I'd be grateful.
>
>Thanks,
>
>Richard.
>
>
>
>  
>


Re: where to put file so web service can read it?

Posted by Ju...@mro.com.
Put your config file under /WEB-INF. You can then read this as follows:

InputStream is = servletContext.getResourceAsStream("/WEB-INF/" +
configFile);

Read this wiki on how to obtain the ServletContext from within your Web
Service:
http://wiki.apache.org/ws/FrontPage/Axis/ServletContext

-Junaid




                                                                           
             Richard Gregory                                               
             <richard.gregory@                                             
             gsf.de>                                                    To 
                                       axis-user@ws.apache.org             
             02/09/2006 09:21                                           cc 
             AM                                                            
                                                                   Subject 
                                       where to put file so web service    
             Please respond to         can read it?                        
             axis-user@ws.apac                                             
                  he.org                                                   
                                                                           
                                                                           
                                                                           
                                                                           




Hi,

I have a web service which needs to read a property from a configuration
file, but I can't work out where in the webapp to put the configuration
file so the web service implmentation class can read it. I've tried
putting it in WEB-INF/classes, in the root directory of the web app, in
WEB-INF, in the same directory as the class which reads it, and in
pretty much every other directory you can think of, but I keep getting a
FileNotFoundException.

If I hard code the full path to the file (C:/..... on Windows or
/home/richard...... on Linux) in my service it can find and read it, but
this isn't really an option as the service will be deployed on different
machines by different customers so the path will vary.

If anyone can give me some suggestions I'd be grateful.

Thanks,

Richard.



Re: where to put file so web service can read it?

Posted by Jim Azeltine <ja...@sbcglobal.net>.
You might try this. It allows you to put the property file in the same directory, and therefore the same package, as your class. You can also jar this and it will still find it, while makes deployment easier. Even though the filename in this case is Connection.properties, you don't need to include the suffix. If you do, it won't find it.
  Just plug the call for this method in a try/catch block, and you should be good to go! 8)
   
   private void loadParams() throws IOException {
     // Loads a ResourceBundle and creates Properties from it
     Properties databaseProperties = new Properties();
     ResourceBundle bundle;
     bundle = ResourceBundle.getBundle("com.performance.Connection");
     Enumeration dbPropEnum = bundle.getKeys();
     String key = null;
     while(dbPropEnum.hasMoreElements()) {
      key = (String)dbPropEnum.nextElement();
      databaseProperties.put(key, bundle.getObject(key));
     }
     // Load the properties file to get the connection information
     m_databaseType = (String)databaseProperties.get("DatabaseType");
     m_hostPort = new Integer((String)databaseProperties.get("Port")).intValue();
 }

Jim
  
Richard Gregory <ri...@gsf.de> wrote:
  Hi,

I have a web service which needs to read a property from a configuration 
file, but I can't work out where in the webapp to put the configuration 
file so the web service implmentation class can read it. I've tried 
putting it in WEB-INF/classes, in the root directory of the web app, in 
WEB-INF, in the same directory as the class which reads it, and in 
pretty much every other directory you can think of, but I keep getting a 
FileNotFoundException.

If I hard code the full path to the file (C:/..... on Windows or 
/home/richard...... on Linux) in my service it can find and read it, but 
this isn't really an option as the service will be deployed on different 
machines by different customers so the path will vary.

If anyone can give me some suggestions I'd be grateful.

Thanks,

Richard.