File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes Reading a properties file from a Web service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Reading a properties file from a Web service" Watch "Reading a properties file from a Web service" New topic

Reading a properties file from a Web service

sanjeewa sanjeewa

Joined: Apr 03, 2008
Posts: 5
I have deployed a webservice in apache-tomcat-5.5.23 using Axis2. (I have placed my .aar file in apache-tomcat-5.5.23\Axis2.war\WEB-INF\services). I need to read a properties file from my web service to read some text dynamically. Could sombody help me to know
1. Where should I place my properties file and
2. How do I specify the path for the properties file to read it in my web service java code.
thanks in advance
Best regards
Doug Slattery
Ranch Hand

Joined: Sep 15, 2007
Posts: 294
Hi sanjeewa,

I'm not 100% sure, but I believe they should go in the axis2 webapp class path
(i.e. ...\tomcat\webapps\axis2\WEB-INF\classes) by default. I haven't needed to put them elsewhere, so I don't know how to configure it (web.xml?). If you put your files there, you shouldn't need to specify the path.

Try that and let me know if it works. I'd be interested in knowing 100% myself .


-- Nothing is impossible if I'mPossible
sanjeewa sanjeewa

Joined: Apr 03, 2008
Posts: 5
Thanks Doug
I tried the location you have specified, (and some other locations as well) but wasn't successful. Once i could solve this, I'll let you know the solution. If any body else could help me on this please....
Best regards
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
What have you tried? Are you using standard file I/O or are you accessing it as a resource through the class loader?
sanjeewa sanjeewa

Joined: Apr 03, 2008
Posts: 5
Just I'm using standard file I/O (Sorry for the delayed response)
Faraz Masood
Ranch Hand

Joined: May 03, 2002
Posts: 55
i guess the problem is with the way you are accessing the properties file

try reading it as getResourceAsStream , and put the file ONLY in child directory of your source code or atleast at the same level ..

for example :

dir1/dira/dir2/ OR
sanjeewa sanjeewa

Joined: Apr 03, 2008
Posts: 5
Hi Faraz Masood,
It works fine great help. Thanks

I put the properties file in the class root and read it like bellow.

String m_FilePath = "/";
InputStreamReader is = new InputStreamReader(this.getClass().getResourceAsStream(m_FilePath));
BufferedReader in = new BufferedReader(is);

Rahul Juneja
Ranch Hand

Joined: Aug 03, 2002
Posts: 425
But this way it doesn't solve the purpose because it is inside the war. and it will require to be build when you change the properties.

Rahul Juneja
ThoughtClicks -
Paolo Milli

Joined: Jul 31, 2009
Posts: 1
I don't know if it's still useful (after more then one year) but I resolve in the follow way:

In order to have the properties file outside the package, I put the file in axis2/WEB-INF/classes

In java code (web service) I have:

InputStreamReader fMainProp = new InputStreamReader(this.getClass().getResourceAsStream(""));
Properties mainProp new Properties();

It works.

Horst Wayne

Joined: Sep 17, 2011
Posts: 1
I had a related problem this week and my research often brought me to this thread so I thought I might post the solution I finally found here:

I am using Axis2 version 1.6.1 and the Axis2 standalone server. I have a JAX-WS annotated web service class, packaged with maven and put as a jar into the repository/servicejars folder.

Now I wanted to read in some database parameters from an external property file (so that I didn't have to redeploy the service when I wanted to change a user name for instance), but I couln't find the solution for a few days.

I tried several different ways to access the file and many possible locations, but always got the same NullPointerException.

Finally, on another forum I found the hint to use a FileWriter to check where the output went, and to my surprise it went straight to the axis root.

So I tried Paolos Code but put the file into the axis root folder and it worked! Then I put it to AXISROOT/conf/database/ and used .getResourceAsStream("/conf/database/")); -- finally I had my solution.

Just thought I'd share this to help someone else who might have the same problem. ;)
I agree. Here's the link:
subject: Reading a properties file from a Web service
It's not a secret anymore!