Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

How to find directory of web app in an axis web service

Thread view: 
jeremy - 19 Apr 2007 20:58 GMT
I've built an axis web service, and I am reading a properties file
using the code below.  The problem is that depending on the
configuration of tomcat, the default location to read the file from
could theoretically be anything.
What I want is to read the file from a subdirectory in the axis
directory, but I don't want to hard code that, so how can I determine
programatically where the axis directory is located, or what the
directory of the web service is?

Properties properties = new Properties();
properties.load(new java.io.FileInputStream("My.properties"));
Arne Vajhøj - 20 Apr 2007 03:44 GMT
> I've built an axis web service, and I am reading a properties file
> using the code below.  The problem is that depending on the
[quoted text clipped - 7 lines]
> Properties properties = new Properties();
> properties.load(new java.io.FileInputStream("My.properties"));

Why not read it as a resource from the classpath ?

Arne
jeremy - 20 Apr 2007 18:29 GMT
> > I've built an axis web service, and I am reading a properties file
> > using the code below.  The problem is that depending on the
[quoted text clipped - 11 lines]
>
> Arne

Can you give me an example of how to do that?
Philipp Taprogge - 20 Apr 2007 22:31 GMT
Hi!

> Can you give me an example of how to do that?

You could do something like this:

class MyClassInsideAWarFile {

 public void someMethod() {
 Properties props = new Properties();
 props.load(this.getClass()
   .getResourceAsStream("/WEB-INF/my.properties");
 }
}

HTH,

    Phil
Lew - 21 Apr 2007 00:29 GMT
> Hi!
>
[quoted text clipped - 10 lines]
>   }
> }

Am I right that that will find a file "WEB-INF/my.properties" relative to an
element of the classpath?

Signature

Lew

Arne Vajhøj - 21 Apr 2007 19:04 GMT
>>> I've built an axis web service, and I am reading a properties file
>>> using the code below.  The problem is that depending on the
[quoted text clipped - 9 lines]
>
> Can you give me an example of how to do that?

Properties p = new Properties();
p.load(getClassLoader().getResourceAsStream("foobar.properties"));

where foobar.properties are either WEB-INF/classes/foobar.properties
or WEB-INF/lib/something.jar!foobar.properties.

Arne


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.