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

J

jeremy

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"));
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

jeremy said:
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"));

Why not read it as a resource from the classpath ?

Arne
 
P

Philipp Taprogge

Hi!

Thus spake jeremy on 04/20/2007 07:29 PM:
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
 
L

Lew

Philipp said:
Hi!

Thus spake jeremy on 04/20/2007 07:29 PM:

You could do something like this:

class MyClassInsideAWarFile {

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

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

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

jeremy said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top