aspose file tools*
The moose likes Web Services and the fly likes Help Reading file in Axis webapp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Help Reading file in Axis webapp" Watch "Help Reading file in Axis webapp" New topic
Author

Help Reading file in Axis webapp

Gobind Singh
Ranch Hand

Joined: Aug 04, 2006
Posts: 62
-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

Joined: Nov 29, 2005
Posts: 2308
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.


Rahul Bhattacharjee
LinkedIn - Blog
Gobind Singh
Ranch Hand

Joined: Aug 04, 2006
Posts: 62
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

Joined: Oct 05, 2006
Posts: 7
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 .
 
 
subject: Help Reading file in Axis webapp