• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Help Reading file in Axis webapp

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-I have deployed axis in tomcat.
-I have written the code for my webservice and packaged it up in a jar and put it in the lib folder.

webapps
|----axis
|----WEB-INF
|-----classes
|-----lib
|-----conf


In the jar file i have a method which needs to read a properties file from the conf folder.

I cant get this method to pick up the properties file using the following statement:
InputStream is = getClass().getResourceAsStream("conf/props.properties");
This is always returning null i.e. it can't find it!
Is it because the file lies outside the JAR?
Can someone tell me what I am doing wrong?

ps: tomcat is being started from C:\jakarta-tomcat-5.5.4\bin
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Gurps Bassi:
-I have deployed axis in tomcat.
-I have written the code for my webservice and packaged it up in a jar and put it in the lib folder.

webapps
|----axis
|----WEB-INF
|-----classes
|-----lib
|-----conf


In the jar file i have a method which needs to read a properties file from the conf folder.

I cant get this method to pick up the properties file using the following statement:
InputStream is = getClass().getResourceAsStream("conf/props.properties");
This is always returning null i.e. it can't find it!
Is it because the file lies outside the JAR?
Can someone tell me what I am doing wrong?

ps: tomcat is being started from C:\jakarta-tomcat-5.5.4\bin



You can use the following code while retrieving inputstream from within a web application.

ServletContext s = getServletContext();
InputStrean in = s.getResourceAsStream("/WEB-INF/conf/props.properties");

That is a better way to get a inputStream from within the web application.
 
Gobind Singh
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would I call getServletContext() on?
My web service code is simple J2SE code which does not deal with servlets, HTTP e.t.c.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i understannd you question properly. Then you can just drop you conf folder in classes folder or create a jar file of conf folder and drop it in lib folder.

Doing so will make you code(i.e "getResourceAsStream()") run.
"getResourceAsStream" function always try to load reosuce from class path and conf is not in the classpath. That's the reason why it was returning null .
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic