This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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 .
 
wood burning stoves
 
subject: Help Reading file in Axis webapp
 
Similar Threads
WebService Problem
Best place for .properties file?
Cannot create JDBC driver of class '' for connect URL 'null'
can't generate java from wsdl file please help!
Cannot create JDBC driver of class 'oracle.jdbc.OracleDriver'for connect URL 'jdbc:oracle:oci:@mydbs