Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help Reading file in Axis webapp

 
Gobind Singh
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
 
Rahul Bhattacharjee
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.
 
Ashkrit Sharma
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 .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic