wood burning stoves 2.0*
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
Author

Reading a properties file from a Web service

sanjeewa sanjeewa
Greenhorn

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
sanjeewa
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 .

Aloha,
Doug

-- Nothing is impossible if I'mPossible
sanjeewa sanjeewa
Greenhorn

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....
Thanks
Best regards
Sanjeewa
Ulf Dittmer
Marshal

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


Ping & DNS - my free Android networking tools app
sanjeewa sanjeewa
Greenhorn

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/mysource.java
dir1/dira/dir2/myfile.properties OR
dir1/dira/dir2/dirx/../dirb/myfile.properties
sanjeewa sanjeewa
Greenhorn

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 = "/Constants.properties";
InputStreamReader is = new InputStreamReader(this.getClass().getResourceAsStream(m_FilePath));
BufferedReader in = new BufferedReader(is);

~Sanjeewa
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 - http://techlabs.thoughtclicks.com
Paolo Milli
Greenhorn

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("myfile.properties"));
Properties mainProp new Properties();
mainProp.load(fMainProp)

It works.

______________________
Paolo
Horst Wayne
Greenhorn

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/db.properties and used .getResourceAsStream("/conf/database/db.properties")); -- 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: http://aspose.com/file-tools
 
subject: Reading a properties file from a Web service
 
Similar Threads
Axis2 class cast exception in tomcat
Generated Servlet class of a jsp.
Reg: Deployment exception
Install Axis2 1.4 on Linux CentOS
Exception: com.microsoft.jdbc